Python first day, python first day
This is something about Python knowledge learned the day before yesterday.
1. Python is a strongly explanatory language.
In Python, you do not need to define the type of a variable. You need to check the type of the variable before running. However, once the type of the variable is determined, if you do not use force conversion to another type, the variable type will not change. If the string type is not converted to an int type, it is not converted to an int type unless the int type is forcibly converted ). Python is an explanatory language, and the source code cannot be encrypted. If you want to encrypt part of it, you can compile it in C language and reference it. If you want to encrypt all the data, compile it in another language.
2. Define Variables
If ";" is not found in Python, you can directly wrap the line after the statement ends. The variable definition method is as follows:
Name = "guoying" # defines variables. strings must be enclosed in quotation marks.
Print (name) # print the variable. () is added after print in Python3, not in Python2.
3. conditional statements and cyclic statements
1. if Condition Statement
If true:
1 + 2 = 3
Elif true:
1 + 3 = 4
Else:
1 + 5 = 6
In Python, if is followed by ":", followed by "else if", only "elif", and forced indent in Python. if you do not indent, an error is reported. The purpose is to make the structure clear and clear.
2. while and for Loops
Python has the while and for loops.
While true:
1 + 3 = 4
Print (4)
This is an endless loop, and the operation will always output 4; unless break is added, the entire loop is ended.
For I in range (10 ):
Print (I)
Obtain. A total of 10 cycles. Range (, 2) indicates that the cycle starts from 0, and the step size is 2. The result is 0, 2, 4, 6, and 8.
Continue indicates that the following loop is not continued and a new loop is started.
For example, for I in range (10 ):
If I> 5:
Continue
Else:
Print ("Hello World !")
This code will only output 6 Hello World! , After I = 6, only the loop repeats until the end of the loop.