First, the composition of Python
The contents of the Python program are mainly composed of variables, data, keywords and operators.
Second, the variable
In Python, a variable is a variable that refers to the data it points to.
First we need to look at Python's memory management. The data is created in memory, but if we do not use a variable to reference the created data, the data becomes a "ghost ghost" and is deleted by Python's memory while it is created.
So the function of a variable is to refer to the data we created in Python, and the data that the variable points to is mutable.
III. provisions of variable names
In fact, you can imagine a variable is a sticky note, which is used to attach to the memory data to identify the data for us. So in order to differentiate between the different sticky (variable), we need to name each variable. The naming convention for variables is only two points: ① can only be composed of 0-9a-za-z and _; ② cannot begin with a number.
Iv. Assigning values of variables
Variable assignment is the process of pointing a variable to the data, and it may be that the variable is pointing poorly and is called a variable assignment. The variable assignment is done by the operator "=". There are several special variable assignment values:
(1) Increment assignment: The process by which a variable and a number are evaluated and assigned to the variable.
Example:
, x+=1 the same results as x=x+1. Other +-*/can also complete similar operations, called self-increment, self-reduction, squared, and self-removal;
(2) Multiple assignments: Point a variable to multiple objects.
Example:
(3) Multivariate assignment: Multiple variables are directed to the same amount of data.
Example:
In general, we want to exchange two variables in the program to point to the data, without changing the data, it is necessary to create a third variable exchange:
But with this mechanism of multivariate assignment, we can do it in one step:
The assignment of variables in Python is evaluated first and then assigned values.
V. Data
The data in Python are: numbers, strings, Booleans, None, lists, tuples, dictionaries, collections, four of which are data structures, which is the container for the information.
Vi. Key Words
The Python keyword is a proprietary character used to identify a specific statement. Such as:
not/and/or: Used to perform boolean operations on data; From/import: For importing packages and modules;
For: iteration loop statement; while: conditional loop statement; If/elif/else: Conditional selection statement; Break/continue: used for interrupting loops;
Del: for deleting objects; print: Printing objects
def: defining functions; Class: Defining Classes
Seven, operator
+-*/: The general known arithmetic operator;
* *: Power operation;
: Floor removal;
%: take surplus;
————————
#: Notes
Single quotes, double quotes, three quotation marks: creating a String
\: Escape character
. : Object's Property Reference
=: Variable Assignment
————————
(): Print an object/create a tuple
[]: Create List/slice operators
{}: Creating a dictionary
Specific reference:
1, "Python Core Programming Second Edition" chapter III
2. Liaoche-Python Basics
1, the basis of Python