1. Learn to view python help
(1) When we want to see which data type the python variable belongs to, we can use
print (type(varible))
(2) When we want to see what specific methods a variable has
varible = dict(a=1, b=2)
print (dir(varible))
This will show all the methods of the variable
(3) After knowing the method, what should I do if the specific method cannot be used?
help(sorted())
or
You can also view usage by pressing Ctrl + left mouse button.
2. Python variable type coercion
for example
age = 100
print ('my age is' + age)
After the above code is executed, an error is reported
Because age is an integer (int), it is printed as a string (str) type
So, do the type conversion before printing:
age = 100
print ('my age is' + str(age))
The output is normal
int() str() dict() list() tuple() is generally a conversion of these types
a = [1, 2, 3, 4, 5]
print (dir(a)) view method
http://www.mimi131.cn