"Hello World"
1 # ! /usr/bin/env python2 # -*-coding:utf-8-*-3 4 Print ('hello,world')
when the line stares: # is annotated content
Multiline Comment: "" "Annotated Content" ""
"Print user input user name and password"
1 a1 = Raw_int ("UserName")2 a2 = Getpass.getpass (" PassWord " )34Print(A1)5Print(A2)
[Ps:getpass.getpass Assigning user input to name variable] does not show password when input |
"Writing and executing Python code flow grooming"1. Create a xxx.py file
PS: Do not have Chinese path
2. Write code
A. Two lines of the head specific
#!/usr/bin/env python (Specify editor path in Linux)
#-*-Conding:utf8-*-
B. Write function code
3. Execute code
A. Open the terminal
Path to the B.python code file
11. Create a xxx.py file2 PS: Do not have Chinese path32. Write Code4 A. Two lines of the head specific5 #!/usr/bin/env python (Specify editor path in Linux)6 #-*-Conding:utf8-*-7 B. Write function code83. Execute code9 A. Open the terminalTenPath to the B.python code file
"python variable"1.python2.7 is using "raw_input" to complete waiting for user input
- Example: 1 raw_input ('>>>')
python3.5 is using "input" to finish the place. User Input
PS: Variables are used to give specific ' things ' to the meaning--variable assignment2. Limitations in Variables
- Variable name: function with numbers, letters, underscores
Example: 1 a1 = ABC 2 A_BC = 123 Example: 1 name1 = "ABC" 2 name2 = name1 so name2 = " /c13>ABC"
- Cannot start with a number
- Variable cannot be a keyword inside python
PS: Write code in the IDE if you encounter an internal variable editor, you will be prompted |
"Basic data Type"1. Number: 1234
2. String:
3. Boolean value:True/falsetrue
- Data is true--a results
- Data is false--b result
Ps:true/false First Letter Capital
|
"Basic conditional statement One"
1 if Condition: established 2 content one 3 content two 4Else : not set up 5 content 6 content four 7
Ps:
- If Else statement
- Symbols written in English
- "=" An equal sign is an assignment
- "= =" Two equals is a comparison
- "! =" does not equal
|
"Basic conditional statement two"
1Name = Raw_input ("UserName") 2PWD = Raw_input ("PassWord") 3 ifName = ="ABC" andPWD = ="123":4 Print('Yes')5 Else:6 Print('No')
"Basic Conditional Statement three"--Multiple conditions comparison
1 if Condition One: 2 xxxx3elif condition Two:4 xxxx5elif Condition Three:6 xxxx7Else:8 AAAA 9
"First real while loop"
"First real while loop"While condition: code block Example:
1 imput Time 2 while True: 3 Print ('1') 4 TIME.SLOSP (1)5 print('end')
- Terminating a while loop with conditional statements
Basic Loop: Example:
1 n1 = True2while N1:3 print(' 123 ' )4 n1 = False5 print('end ')
- Break: Used to jump out of the current loop, and the code below the break is not executing.
- Conttinue: Used to jump out of this loop and continue the next cycle
Python diary--writing python for the first time