Basic Python knowledge (1): Basic python knowledge
First, it is very convenient for beginners to set up multiple programs for execution in a project, so that they can easily practice and test different knowledge points.
For commercial projects, there is usually only one executable Python program in one project.
I. Notes
To improve readability, comments should leave at least two spaces in the code
- Single line comment (line comment)
- Start with #, and the text on the right is the best description # Add a space to keep the code elegant ~
- (One-click modification)
- Multi-line comments (Block comments)
Ii. debugging
1. Set breakpoints
2. One-Step debugging of F8
3. F9
4. Ctrl + F2 stop debugging
5. shift + F9 will directly open a new debugging environment, preferably F9 to continue and then execute shift + F9.
Iii. Arithmetic Operators
1. Operators
PS in Python * can also be used in strings. The calculation result is the result of a specified number of times of repeated strings.
2. Priority
- Multiplication, division, and addition and subtraction
- Same-level operators are calculated from left to right.
- You can use () to adjust the computing priority.
** Power (highest priority)
*/% // Multiplication, division, remainder, and integer
+-Addition and subtraction
Iv. Variables
- You can directly use the previously defined variables.
- Variable names are defined only when they appear for the first time.
- The variable name appears again, instead of defining the variable, but directly using the previously defined variable
In Python, you do not need to specify the type of the variable when defining the variable. At runtime, the Python interpreter automatically exports the exact type of the data stored in the variable based on the data on the right of the equal sign assigned to the statement.
1. Type
Number Type
- INTEGER (int)
- Int (integer)
- Long (long integer)
PS (3.0 in Python2.7 and then merged)
- Float)
- Boolean (bool)
- True: Non-0 values -- Non-zero: True
- False
- Complex)
- It is mainly used for scientific computation, such as plane field, fluctuation, inductance and capacitance.
Non-numeric type
- String
- List
- Tuples
- Dictionary
The type function can view the type of a variable.
type(name)
2. Computing
(1) digital
(2) balanced
(3) The numeric and numeric types cannot perform any other operations.
3. Input
To obtain user input information on the keyboard, you must use the input function (interactive)
PS (Python) is considered a string.
String variable = input ("prompt message :")
Type conversion functions
- Int (x) converts x to an integer.
- Float (x) converts x to a floating point number.
The built-in function input () in Python2.7 regards the input data as a command. raw_input () should be used to input data from the keyboard ()
In Python3, the input () function is used to read data from the keyboard.
4. format the output
Print ("formatting string" % variable 1) print ("formatting string" % (variable 1, variable 2 ...))
The following two figures explain a writing habit error caused by an operational nature of the string, and parentheses are added to indicate that arithmetic operations can be performed first;
5. Name
Identifier
Keywords
# View the keyword import keywordprint (keyword, kwlist) in Python)
Naming rules
1. (Guido jiduo-specifications recommended by benevolent arbitration personnel)
2 ,(Hump naming method)
- Small hump naming method
- The first word starts with a lower-case letter and the first letter of a subsequent word is capitalized.
- For example, firstName and lastName
- Big hump naming method
- The first letter of each word is an uppercase letter.
- For example, FirstName and CamelCase