Table of Contents of Series Articles
Day1 self-study python-print function, escape characters, identifiers,
Article directory
1. Data type
integer type
- English is integer, abbreviated as int, which can represent positive numbers, negative numbers and zero.
- Different base representations of integers:
Decimal → Default base
Binary → Starting with 0b
Octal → Starting with 0o
Hexadecimal → Starting with Ox
floating point type
- Floating point number consists of integer part and decimal part
- Floating point storage inaccuracy
When using floating point numbers for calculations, the number of decimal places may be uncertain.
Solution: Import module decimal
Boolean type
- A value used to represent true or false
- True means true, False means false
- Boolean values can be converted to integers
True→1
False→0
string type
- String is also known as immutable sequence of characters
- Can be defined using single quotes ' ', double quotes " ", triple quotes or ''' '''
- Strings defined by single and double quotes must be on one line
- Strings defined by triple quotes can be distributed on multiple consecutive lines
2. Data type conversion
Why is data type conversion needed?
Splicing data of different data types together
3. Comments
- Annotation text in the code that explains the function of the code can improve the readability of the code.
- The content of the comment will be ignored by the Python interpreter
- Usually includes three types of comments.
Single-line comments → start with "#" and end with a newline.
Multi-line comments → there is no separate multi-line comment mark. The code between a pair of three quotation marks is called a multi-line comment.
Chinese encoding statement comment →Add a Chinese declaration comment at the beginning of the file to specify the encoding format of the source code file. python3 defaults to UTF-8
4. input function
Function: Receive input from the user
Return value type: The type of the input value is str
value Storage: Use = to store the input value
present=input('请输入')
5. Operators
arithmetic operators
Standard arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/),
integer division (//) remainder operator: %
exponentiation operator: **
assignment operator
Execution order: right → left
Supports chain assignment a=b=c=20, pointing to the same memory area
Supports parameter assignment +=, -=, *=, /=, //=, %=
Supports series unpacking assignment a ,b,c=20,30,40
comparison operator
Compare the size, true and false, etc. of the results of variables or expressions.
The result of the comparison operator is of bool type.
An = is called the assignment operator, and == is called the comparison operator. A variable consists of three parts: identification, type, and value
= = What is compared is the value, and the identification of the comparison object uses is
boolean operator
Bit operations
Convert data into binary calculations
operator precedence
Bits and & - If the corresponding digits are all 1, the result digit is 1, otherwise it is 0.
Or | - If the corresponding digits are all 0, the result digit is 0, otherwise it is 1.
Left shift operator << - High bit Overflow is discarded, low-order bits are filled with 0s.
Right shift operator >> - low-order bits are overflowed and discarded, and high-order bits are filled with 0s.