One, the code
By default, Python3 source files are encoded in UTF-8, and all strings are Unicode strings. Of course you can also specify a different encoding for the source file:
1 #-*-CODING:GBK-*-
Second, identifiers
1. The first character must be a letter or underscore ' _ '.
2. The other parts of the identifier are made up of letters, numbers, and underscores.
3, the identifier is case sensitive.
In Python3, non-ASCII identifiers are also allowed.
Third, Python reserved word
Reserved words are keywords, and we cannot use them as any identity names. Python's standard library provides a keyword module that can output all the keywords for the current version:
>>> import keyword>>> keyword.kwlist[' False ', ' None ', ' True ', ' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' finally ', ' for ', ' from ', ' global ', ' if ', ' import ', '-', ' is ', ' LAMBD A ', ' nonlocal ', ' not ', ' or ', ' Pass ', ' raise ', ' return ', ' Try ', ' when ', ' with ', ' yield ']>>>
Iv. notes
# single Comment
"" or "" "multi-line comment, three single (double) quotation marks are paired, you can also use this symbol to represent a piece of content
Five, line and indent
Python's most distinctive feature is the use of indentation to represent the code block structure. The number of spaces to indent is variable, but the same number of indentation spaces must be used within the same code block
Vi. Types of data
The Python data type has
Numbers (digital)
String (String)
List (lists)
Tuple (tuple)
Sets (collection)
Digital type:
Categories in digital: integers, long integers, floating-point numbers, and complex numbers
Integers: 1
Long integer: is a larger integer
Floating-point bellow: 1.23 3E-2
Plural: 1 + 2j, 1.1 + 2.2j
String:
* The single and double quotation marks in Python are used exactly the same.
* Use three quotation marks ("' or" ") to specify a multiline string.
Escape character ' \ '
Natural characters, by adding R or R before the string. Such as
Print (r "This was a line with \ n") shows the result this is a line with \ n
The string is immutable
cascading strings by literal meaning, such as
>>> a = "This" "was" "string" >>> a ' this is string '