By default, the Python3 source file is encoded in Utf-8.
Identifiers are numbered, alphabetic, underlined, and the first letter does not apply to numbers. is case sensitive.
Annotate with #: #这是注释
Use indentation to represent a block of code, without curly braces {}. However, statements within the same code block must contain the same number of blank cells:
if True: Print ("True") Else : Print ("False")
Use backslashes \ To implement interlacing:
Total = Item_one + + item_three
View Code
Multi-line statements in (), [], {} Do not require a backslash:
1 total = ['item_one'item_two'item_ Three',2 'item_four' item_five ']
There are only four types of numeric values :
integers, long integers, floating-point numbers, complex numbers (1.1+2.3j)
string :
* Single quotes and double quotes work the same
* Three quotation marks can specify a multiline character
* Escape character "\"
* string preceded by R or R, the escaped string will be displayed as an acoustic string: R "This was a line with \ n"
* string is not variable
* String pre-plus u, as Unicode processing
Blank line :
The function or class method is separated by a blank line.
The print () statement outputs a line wrap, which can be added end= "":
# No line break output Print (x, end="" ) Print (Y, end="" ) Print ()
View Code
code group :
Indenting the same set of statements is called a code group. The first line of If/esle, while, starts with the keyword and ends with a colon (:). The code group after the first line becomes a clause.
if expression: suite # clause elif expression: Else : Suite
Module Import:
entire module import: Import Somemodule Import a function of a module: # Import a from Import somefunction # Import Multiple from Import Firstfunc, Secondfunc, Thirdfunc # Import All from Import *
View Code
Command-line arguments:
Python can use the-H parameter to view the Help information for each parameter
The variable does not need to be declared, and is created after the value is assigned. The variable itself has no so-called "type", generally refers to the type of object that it refers to in memory.
Multiple variables can be assigned values such as: a=b=c=1
Or: A, B, C = 1, 2, "Runoob"
Standard data types
Number:int (long) float (floating point) bool complex (plural)
Language built-in type () function query type print (type (a))---"<class ' int ' >
Type () differs from instance (). Type Otherwise the subclass instance belongs to the parent class instance admits that the instance of the subclass belongs to the parent class type.
Division operator/always return a floating point, to take integer with//operator
When blending, Python converts the integer type to floating point.
String
Tuple
List
Sets
Dictionary
Python basic syntax