1. Constants
Python constants are different from C # constants. Python constants do not have a name. Such as 2, 1.5, 1.2e-3, or 'this is a string', "It's a string. Unlike C #, it must be identified by the const keyword.
2. Number
Python has four types of numbers: integer, long integer, floating point, and plural. Example:
* INTEGER: 2
* Long Integer: an integer greater than 65535
* Floating point: 1.2, 1.2e-3, e is the power of 10, and 1.2e-3 indicates 1.2*10-3
* Plural: (-5 + 4j), (1.2 + 2.3j)
3. String
Python does not have the char type. Single quotes and double quotes are exactly the same. Example:
* Single quotes: 'quote me on this'
* Double quotation marks: "waht's your name"
* Three quotation marks: ''' this is the first line.
This is the second line .'''
Or
"What's your name?
My name is known ."""
* Escape Character: 'What \'s your name? '
* Natural string: Start with R or R, R "Hello world! \ N"
4. Variables
Identifier naming rules:
* The first character is a letter (both uppercase and lowercase) or an underscore (_)
* Other characters are uppercase/lowercase letters, numbers, and underscores.
* Case sensitive. myname and myname are two different variables.
5. Data Type
The basic data types of Python are numbers and strings, and the advanced types are classes.
6. Object
Python regards everything as an object, and it regards the number 2 as an object.
7. logical and physical rows
The physical line is what you see in the editor. The logic line can be identified by python. Generally, Python considers a physical row to correspond to a logical row.
If you want to use multiple logical rows in a physical row, you must use a semicolon (;) to separate the rows. A semicolon indicates the end of a logical row or statement. We recommend that you do not write it like this, which is less readable.
Example: I = 5; print (I)
Equivalent
I = 5
Print (I)
If you want to write a logical row in multiple physical rows, use a backslash (\) to connect.
Example: S = "This Is \
String"
Equivalent
S = "this is a string"
8. indent
Indentation is important in Python. The blank at the beginning of the line is important, for example:
Print ("hello ")
Print ("world ")
The second print statement reports an error because there is a blank error before it.
Statements at the consent level must have the same indentation.
Do not mix spaces and tabs, so that they will not work on different platforms.
We strongly recommend that you use a single tab or two or four spaces when indent. We recommend that you use four spaces as always.