Base: 1. The first sentence of Python usage
- Python does not limit the suffix name, it can be arbitrary
- When importing a module, if it is not a. py file (the file suffix later is py)
Usage of 2.input:
- Wait forever until the user enters a value. The input value will be assigned to one thing.
3. Variable Name:
- -Alphabet
- -Digital
- -Underline
PS: numbers cannot begin; It is not a keyword; it's best not to repeat what Python has built-in
Keywords: [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ' , ' from ', ' global ', ' if ', ' Import ', ' on ', ' is ', ' lambda ', ' no ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' with ', ' yield ']
For example:
1 " Welcome to your arrival! " #变量 2Print(A1)3 ===========4print( " Welcome to your arrival. ")
4. Conditional Statements
- If condition (code block at one level after a conditional statement)
1 if Conditions: 2 Print ("OK") 3 Else : 4 Print ("Error")
1 if1=1:2 if2=2:3 Print("Hello")4 Print("Hello2")5 Else:6 Print("Error")7 Else:8 Print("Error2")
- If elif multi-condition judgment
1INP = input ('Please enter your membership level:')2 ifINP = ="Senior Member":3 Print('Welcome to Senior members')4 elifINP = ="Platinum Members":5 Print('Welcome Platinum Members')6 elifINP = ="Diamond Members":7 Print('Welcome Diamond Members')8 Else:9 Print('Welcome to Ordinary members')Ten Print('Welcome to our store ...')
Knowledge Points: If basic statement Else
Add: Pass means empty code, meaningless; only used to represent blocks of code. If Python does not want to output anything, the write pass skips directly without outputting any statements.
5. Basic data types
- String (quotation marks):
1 " Alex " 2 ' Alex ' 3 """ Alex """ 4 " " Alex " "
How to use the string:
1 addition:2N1 ='Alex'3N2 ='Tom'4N3 = n1+N25 Print(N3)#Output Effect Alextom6 7 multiplication:8N1 ='Alex'9N2 = n1*10Ten Print(N2)#Output Effect Alexalexalexalexalexalexalexalexalexalex
1 eg:2Age = 193 4 Add, subtract, multiply, divide, Zhifang, take surplus:5A1 = 106A2 = 207a3 = A1 +A28a3 = A1-A29a3 = A1 *A2TenA3 = 100/10 OneA3 = 3**4#get 3 of the 4-time Square Aa3 = 39% 8#get 39 divided by 8 to get the remainder -A3 = 39//8#get 39 divided by 8 to get the quotient - the judging odd and even numbers; -A = 15 -temp = a% 2 - iftemp = =0: + Print('even') - Else: + Print('Odd')
6. Cycle
1 import time 2 while 1 = = 1 : 3 print ( ok , Time.time ())
1 Import Time 2 count = 03 while Count <:4 print( Count)5 #count =6 count = count + 17 Print(123)
Ps:
1.while .... else loop
2.continue terminates the current loop and begins the next cycle; Break terminates so loop
Python Basic & conditional statements