Basic data types
Data: Status Description of the measure data
Type: different things require different types of storage
-
Int int
Definition: age, phone number, etc. is an integer number
B string into integer
b = '12 is'
Print ( type ( b))
b = int ( b)
Print ( type ( b)) < class 'STR' > < class 'int' > -
Float float
Definition: weight, height and so there is a decimal point
= F1 1.9 # F1 = a float (1.9)
Print ( type ( F1)) < class 'a float' > string into float F2 = '1.9' F2 = a float ( F2) Print ( type ( F2)) < class 'a float' > -
String str
Definition: keep some descriptive information, keep personal interests, personal profiles
String quotes are no different, but can not be mixed.
If the string needs quotation marks, it must be nested. # S2 = 'asas "sd"'
s1 = 'sean' #s1 = str(sean)
print(type(s1))
print(id(s1))
print(s1)
<class 'str'>
2945322521392
seanpython2:
STR nature actually have a bit with 8-bit serial to python3: STR sequence unicode nature actually 1024G 1T = 1024M. 1G = 1024KB = 1M 1024B = 1KB . IB = 8bit
String concatenation is to open up a new memory space, the value after you deposit into stitching.
s3 = 'hello'
s4 = 'world'
print(s3 +s4)
helloworld -
List list
Definition: a stored value or a plurality of different types of
In the count is zero programming
Y = [ 'elephant', 'beautiful', [ 'Read', 'Study']]
Print ( Y)
Print ( type ( Y)) Print ( Y [ 0]) print result: [ 'elephant' , 'beautiful', [ 'Read', 'Study']] < class 'List' > elephantIn the list there is a list of values. = L1 [ [ 'Egon', 73 is, 'hot head', [ 'singing', 'jumping', 'RAP']], [ 'Alex', 84, 'beauty'] ] Print ( L1 [ 0] [ . 1]) Print ( L1 [ . 1] [ 2]) Print ( L1 [ 0] [ . 3] [ 2]) print result: 73 beautiful rap
-
Dictionary type dict
The method defined: {} stored data by key: value defines the mapping relationship between key-value pairs,
Each value is separated by commas.
d1 = {"name": 'sean', 'age': 18} # d1 = dict({"name":'sean','age':18})
print(d1['name'])
print(type(d1))
d2 = {'name':'tank','age':73,'hobby':[ 'piao', '妹子']}
print(d2['hobby'][0])
打印结果:
sean
<class 'dict'>
piao -
Boolean
Definition: mainly used to judge right and wrong things
General does not define a separate boolean
tag = True # tag = bool(True)
tag1 = False # tag = bool(False)= A . 1
B = . 1
Print ( A == B) # equal sign is the comparison value (value)
Print ( A IS B) # IS comparison is id (address) print result: True True