First, the opening of the large section of poisonous chicken soup is really enough to fill. Just outside the tour, all the time with headphones on the whole hearing.
Second, enter the subject, the results are introduced. Next version problem, try to use Python3.
Third, Hello world. It's a ceremonial feeling, nothing else.
Print ("Hello")
Iv. variables. Although the hump rule is OK, but Python is recommended to use _ underline, that is underlined. Variable name all uppercase denotes constant
Five, character encoding. Unicode: All characters are 2 bytes. The UTF-8:ASCII code accounts for 1 bytes, and the Chinese characters are 3 bytes. Recommended UTF-8
Vi. comments. Single-line comment with #, multiline comment with 3 straight (or double) quotes ("" or "" ")
The content between seven and 3 quotes can also represent a string that spans a line. Formatting across rows of strings (variables appear in the middle)
with + stitching. is not recommended and is inefficient because it opens up a memory unit for each piece of content
This is not recommended with%s%d%f, but can be used
str = ("" "=====%s Information ===== user name:%s Sex:%s Age:%d" ""% ("Zhang San", "Zhang San", "Male", ")" Print (str)
Use the {number or new variable name}, and use. Format () To recommend this method after the quotation mark ends. Here are 3 examples:
str = ("" "====={} information ===== user name: {} gender: {} Age: {}" "". Format ("Zhang San", "Zhang San", "Male", ")" Print (str) str = ("" "====={name} Information ===== Username: { Name} Gender: {Gender} Ages: {age} "" ". Format (name=" Zhang San ", gender=" male ", age=24)) print (str) str = (" "" ====={0} Information ===== Username: {0} Gender: {1 } Age: {2} "" ". Format (" Zhang San "," Male ",") "Print (str)
Eight, user interaction program. Input ("Hint content:"). To enter a password, you can refer to import Getpass at the beginning, and then call Getpass.getpass ("Password:") in the program. Getpass can only be used in the system, pycharm or idle will be error.
Import getpassusername = input ("Please enter user name:") Password = getpass.getpass ("Please enter password:") print (Username,password)
Nine, conditional judgment and circular statement. The code block needs to be indented, and there is no need to end with an end. It is also necessary to use the indentation to beautify and easy to read.
If Else
num = 50guess = Int (Input ("Enter Number:")) if num = = Guess:print ("guessed") Elif guess > Num:print ("Big Up") Else:print ("Small A ")
While
n = 1while n<10:print (n) n +=1
For
For I in range: print (i)
The continue in the loop, which means that the next time the loop is skipped for execution. Break means jump out of the loop
For I in range: if i%2 ==0:continue print (i) n = 1while true:print (n) n +=1 if n>10: Break
The for And while loop statements can end up with an else, which executes when the normal exit loop is executed, with break out of the case
n = 1while n<10:print (n) n +=1 key = input ("Enter Q exit, otherwise continue") if key = = "Q": Breakelse:print ("loop normal fallback Out ") Print (" End loop ")
Python Automation Development Learning 1