Python suitable for network siege lion learning-basic grammar (variables)

Insert picture description here

1. Definition

The so-called variable is the amount by which the value will change during the running of the program. Relative to variable constants, the common naming method in Python is to use all capital letters to specify constants, PI=3.1415926.

Variables are used to point to an object stored in memory, and each object can represent different data types according to its own situation. Through the operation of variable assignment, the variable points to an object.

For example a=10
Insert picture description here

The equal sign = to connect the variable name and value, and then complete the operation of variable assignment.

Two, type () function

Use the type() function to confirm the data type of a

Insert picture description here
The data type of variable a is int (integer)

Python is a dynamically typed language, it is not as rigid as C and Java
Insert picture description here
Use the type() function to automatically confirm the data type

Three, variable name requirements

  • Uppercase and lowercase English letters, underscores, and numbers can be represented
  • Cannot contain punctuation marks, spaces and various other special symbols (parentheses, currency symbols)

1. Variable names can start with letters and underscores, but cannot start with numbers
Insert picture description here

The python interpreter returned an error message of "SyntaxError: invalid syntax" which is an invalid syntax, and 123c is an invalid variable name. This is the advantage of the python interpreter"Timely feedback".

2. Variable names are case sensitive

Insert picture description here

3. If two or more words appear in the middle of the variable name, they can only be connected by underscores, and spaces cannot be used to separate them

Insert picture description here

4. Not all English words can be used as variable names, there are some in PythonReserved word

Insert picture description here

The return value of print (keyword.kwlist) is a list. The elements in the list are reserved words in python, and these reserved words cannot be used as variable names.

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44309905/article/details/114789738