Single-line comments : With # start
Multiline comment : Use multiple # Number
Start and end of multiline use ''' perhaps """
Statements in the same code block must contain the same number of indented spaces
The number of spaces in the indent number is inconsistent , Can cause a run error
Python It's usually a sentence written one line at a time , But if the sentence is long , We can use backslash \ To implement multiline statements
In addition : stay [], {}, or () Multiple lines in , No need to use backslash \;
Backslash can be used to escape , Use r You can keep the backslash from escaping . Such as r"this is a line with \n" be \n Will be displayed , It's not a new line
4、 Show multiple statements on the same line , Use ; separate
In addition
When you specify a value ,Number The object will be created :var1=1
By using del Statement to delete a single or multiple object :del var1,var2
type() Function can be used to query the object type of variable
You can also use isinstance To determine the type of data , The return value is TRUE perhaps FALSE
The difference between the two is as follows :
Be careful :Python3 in ,bool yes int Subclasses of ,True and False Can be added to numbers , True==1、False==0 Returns the True, But it can go through is To judge the type .
2.3、 Numerical operation
2 / 4 # division , Get a floating point number
0.5
>>> 2 // 4 # division , Get an integer
0
>>> 17 % 3 # Remainder
2
>>> 2 ** 5 # chengfang
32
Be careful :
Python Use single quotes for strings in ' Or double quotes " Cover up , Use the backslash at the same time \ Escapes special characters .
Be careful :
The types of elements in a list can vary , It supports Numbers , Strings can even contain lists ( The so-called nested )
The list is written in square brackets [] Between 、 Comma separated list of elements
Just like a string , The list can also be indexed and intercepted , After the list is truncated, a new list containing the required elements is returned
Be careful :