I. Constants and Variables
Data types in 1.python
Category:? Number: Numeric "integer, float, plural"
? String: Type
? Boolean: boolean "True,false"
? None: null value
? List: Lists
? Tuple: Tuples
? Dict: Dictionary
? Set: Set
Integer: can handle integers of any size, support binary
Floating-point type: At the bottom of the computer, floating-point notation is based on the scientific notation "123.456----" 1.23456e2 "
Plural: mathematically: a+bi,-------"A+BJ
String: Is any text enclosed in single or double quotation marks, "' A '"
Boolean: Only two values, true,false, relational operators, and logical operators are generally Boolean values
2. Constants
definition: An identifier in which the value never changes during a program's run
Example: Print ("1") Print ("abc") Print ("True" ) 3. Variables
3.1 Concepts
Definition: An identifier in which a value can change arbitrarily during a program's run
Functions: Storing data, participating in operations
Syntax: identifier = value
Description: The identifier is referred to as the variable name "reference", the first time the value of the variable is called the initial value, = is called the assignment operator
Attention:? A. Variable names are subject to the definition rules and specifications of identifiers
? B. The definition of a variable creates a space in memory and then stores the data in this space "because Python is the language of the Dynamic data type, what type of data stored in this space cannot be determined"
3.2. Use
1. Definition: a = 1 &nbap; STR1 = "ABC"
2. Name: Student_name = "Zhang san" studentname = "Zhang San"
If a variable is not defined, it cannot be used, such as print (' num ') #会报错
3. Variables are used to store data, improve the maintainability of the code, and if you do not want to change the value of a variable, capitalize the variable name at name
3.3. In-Memory variables
Variables open up space in memory, so how do we release them?
Manually freeing memory and automatically freeing memory
1. When there is no variable name or reference point to an entity, then the entity is treated as garbage, and can only wait for the system to reclaim it, to achieve the release of memory, so that the next re-use
2. When the variable is deleted, the variable will no longer be used, equivalent to the variable not defined, syntax: del variable name
3.4. Summary of variables
Characteristics:
? A. The value of a variable can change at any time
? B. Use of variables requires space in memory
? C. The meaning of variables: to store and process variable data in life
Two. Operators
1. Arithmetic operators: +-*/% "redundancy, modulo" * * "exponentiation"//"rounding"
NUM1 = 5
num2 = 3
Print (NUM1 + num2)
Print (NUM1-NUM2)
Print (NUM1 * num2)
Print (NUM1/NUM2)
Print (num1% num2) #2
Print (NUM1 * num2) #125
Print (NUM1//num2) #1
#注意: At the bottom of the computer, the data is processed in the form of a complement
#思考问题: The precedence of the exponentiation operator is higher than the multiplication operator in the arithmetic operator
Print (2 * * 5 * 3) #96
Print (2 * 5** 3) #250
Print ((2 * 5) * * 3) #1000
2. Assignment operator: simple assignment operator: = Note: first operation = right, then the result is assigned to = left variable
Compound assignment operator: + = = *=/= ..... "Combination of arithmetic and simple assignment operators"
3. Relationship "conditions, comparison" operator: = = = "Not equal" < > <= >=
4. Bitwise operator "Understanding": Note: The bottom of the computer is treated as a binary way
& Bitwise AND | bitwise OR ^ bitwise XOR or ~ bitwise inverse << shift left >> shift to right, or move on
Print (6 & 3)
Print (6 | 3)
Print (6 ^ 3)
Print (~)
Print (6 << 2)
Print (4 >> 2)
Print ( -6 >> 2)
Python Learning Path 03