I. Types of numbers
1, integer int
That's the integers: 100, 200, 2, 3, 4 -------
2、Float type float
Decimal: 1.22, 1.32, 1.00 ------
3、Built-in function--type
type (the name of the variable or variables that have been assigned values)
count=100 print(type(count)) print(type(1.14))
II. String Types
1. What is a string:
(1) What you see in the book are strings.
(2) Strings wrapped in ' ' or " "
(3) Strings can contain any characters: letters, numbers, symbols and in no particular order.
(4) In Python, using thestrto represent string types, and strings can be defined through this function class:
safe = str('will rely on ') name = 'Little Ming' message = 'Yeah' in = 'hao '
2. Built-in functions for strings:
3. The important idea of strings:
(1) Strings are immutable
The built-in function id of.
(1) Returns the memory address of the variable
name = 'xiaohua' x=id(name) print(x) name='xiaoming' y=id(name) print(y)
This way you can also see why it is said that strings are immutable
(2) Digital address = id (variable)
Built-in function len.
(1) Returns the length of the string
(2) Cannot return the length of a numeric type
(3) return value = len(string)
lenggth=len("w hen hao ") print(length)
name = 'xiaohua' x=id(name) print(x) name='xiaoming' y=id(name) print(y) new_name=name print(id(new_name)) info=''' Too mushy. ''' print(info) info1="ni" info2='ni' new_str= "hello world!'yes'" print(new_str) new_str1= 'hello "world"!yes' print(new_str1)
6. String utilization:
(1) Use of the built-in member function in
The membership operator is used to determine if the member you want is present in your data
(2) Built-in function max
Returns the largest member of the data
(3) Built-in function min
Returns the smallest member of the data
(4) Accumulation of strings
To be precise, it's actually a concatenation of strings, using the symbol "+".
# coding :utf-8 str1='I love python so much' flag1='Like' in str1 flag2='python' not in str1 print(flag1) print(flag2) str2='Weather' str3='That's nice.' print(str2+str3)
III. Boolean types
1. What is a boolean type, boolean type fixed value
Determining true and false is the Boolean type
Fixed values: True,False
2. Scenarios for using Boolean types
Scenarios for determining authenticity
3. Use of Boolean functions
bool represents a boolean type, which can also be used to determine whether the result is true or false.
4. Numbers, strings on boolean types (built-in function bool)
0->False
Non-0->True
0.0->False
Non-0.0->True
str''->False (i.e. empty string)
Non-empty string ->True
IV. Empty types
1. Empty type None
Not belonging to any data type is the null type
2. Fixed values
It's None.
The empty type is False
V. List types
1.What is a list
A list is a queue.
He is a collection of various data types and a data structure.
A list is a type of collection that is ordered and has repeatable content
2. Definition of a list
Use list to represent a type of list, or you can use it to define a list.
The elements of the list exist in a [] with a
A list is a data structure of unlimited length, but don't create super-large lists!
3. Types in the list
string type
integers
floating point type
bool type
empty type
List types (nested)
The use of max, min in lists.
1 in [1,2,3,4] =>true
max([1,2,3,4]) =>4
min([1,2,3,4])=>1
When max and min are used in a list, the elements in the list cannot be of more than one type.
# coding :utf-8 li=list[None,None,None] li1=[1,2,3] print(li) print(li1) max_list=[1,2,3,4] print(max(max_list)) print(min(max_list)) li2=[1,2,'jiafa','We','Ture'] print(li2)
VI. Tuple types
1. What is a tuple
Like a list, it is a queue that can store multiple data structures
A tuple is also an ordered set whose elements can be repeated.
2. Definition of tuple
The tuple represents the type of tuple, which can also be used to define a tuple
The elements of a tuple exist in a ( ) parenthesis
If there is only one member, follow it with a comma
The difference between a tuple and a list
Tuples take up less resources than lists
Lists are mutable, tuples are immutable
Types in tuples
integers
floating point
string (computer science)
listings
bool type
None type
Tuple types (nested)
Use of in, max, min in tuples
Same as the list.
#coding utf-8 tuple_test=('xiao ming',)# An element should be followed by a comma print(tuple_test) print(type(tuple_test))
VII. Dictionary types
1. What is a dictionary
A dictionary is a data type consisting of multiple keys and their corresponding values.
2. Dictionary structure and creation methods
dict stands for dictionary and can create a dictionary
Storing a key and a value in a dictionary via {}
3. Data types supported by the dictionary
The key supports string, number and tuple types, but lists are not supported.
value supports all python datatypes.
4. Dictionaries in lists and tuples
_list=[{1:1,2:3},{‘one':1,‘two':2}]
_tuple({1:2},{‘one':1})
In python 3.7 and earlier dictionaries are unordered
5. Important features in the dictionary
The key in the dictionary is unique
To this article on the basis of Python data type knowledge summary of the article is introduced to this, more related Python data type content, please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!