First, the role of the five types of data of the python brief, defined manner using the method
Digital Type
Integer
Role: Description ID, Student ID, etc.
Defined way
a = int(123)
Float
Role: height description, salary, etc.
Defined way
a = float(20000.0)
String type
Role: Description name, hobbies, etc.
Defined way
a = 'byx' b = "byx" c = ''' a b c '''
Instructions
a = 'my name is ' b = 'byx' print(a + b) # 'my name is byx' print(b * 2) # 'byxbyx' print(a > b) # True
List
Action: is capable of storing a plurality of sets of data of any type, and can be easily taken out one or more.
It is defined by: a plurality of data separated by commas within brackets.
Instructions
l = [1, 2.3, 'a', ['b', 'c']]
dictionary
Action: is capable of storing a plurality of sets of data, there are stored data corresponding to the description
Is defined by: a plurality of memory elements braces, elements are key: value format stored key-value pairs separated by commas
Instructions
dic = {'a': 1, 'b': 2} dic = dict(a = 1, b = 2, c = 3) print(dic[a]) # 1
Boolean
Role: right or wrong thing or feasibility logo
Use
tag = True tag = False
Second, the line of code to achieve the following function codes
x = 10
y = 10
z = 10
x = y = z = 10
Third, the exchange of two ways to write x, y values
x = 10
y = 20
z = x
x = y
y = z
x, y = y, x
Fourth, write a line of code in the first 2,3-loving nick
nick_info_dict = {
'name':'nick',
'age':'18',
'height':180,
'weight':140,
'hobby_list':['read','run','music','code'],
}
res1, res2 = nick_info_dict['hobby_list'][1], nick_info_dict['hobby_list'][2]
Fifth, formatted output using the following three ways output
name = 'byx'
height = 180
weight = 140
# "My name is 'Nick', my height is 180, my weight is 140"
print(f'My name is {name}, my height is {height}, my weight is {weight}')
print('My name is %s, my height is %s, my weight is %s' % (name, height, weight))
print('My name is {}, my height is {}, my weight is {}'.format(name, height, weight))