In Python, variables do not need to be declared in advance. When they are created, they can be assigned directly. The variable type is determined by the value assigned to the variable. It is worth noting that once a variable is created, it needs to be assigned a value.
The following rules shall be strictly followed for variable names:
1. Variable name can only contain letters / numbers / underscores
2. Number cannot start
3. Can’t say the keyword of Python
4. It cannot be a function name, otherwise it will lose its function.
#!/use/bin/env python #-*- coding:utf-8 -*- Content5 = 6 ා Content5 is the value of variable name 6 Print (type (Content5)) (output type is' Int ' _Value = 'name of variable' × value is variable name 'name of variable' is value of variable Print (type (﹐ value)) ﹐ output type is' STR '
How to view Python keywords?
import keyword Print (keyword. IsKeyword ("and")) (judge whether and is a keyword #Output true after running Print (keyword. Kwlist) - view all keywords in Python
It cannot be a function name, otherwise it will lose its function function.
Len = 'special character channeling name' ා use len as variable name print(len) Print (len (strexample)) (len function loses the function of returning string length, resulting in system error. Output is: Special character names Traceback (most recent call last): File "D:/pystudy/aaaa.py", line 15, in print(len(strExample)) NameError: name 'strExample' is not defined