First, if the use of several information
1. If basic statement
If 1==1: print (' OK ') #缩进四个字符, you can press the TAB key else: print (' Error ')
If 1 = = 1: Print (' A1 ') print (' A2 ') print (' End ')
2.if nesting
if1 = = 1: if2 = = 2: Print('A1') Print('A2') Else: Print('A3')Else: Print('A4')
3.if elif
INP = input ('Please input INP:')ifINP = ='A1' : Print('B1')elifINP = ='A2': Print('B2')elifINP = ='A3': Print('B3')Else: Print('B4')
4. Use pass to represent the empty code, meaningless, only to represent the code block
if 1 = =1 :passelse :print(' A1 ')
II. Basic data types
1. String (symmetric quotation marks, format not unique)
Addition:
n1="Alex"n2='nb'n3=n1+n2 Print(n3)
>> output is ALEXNB
Multiplication:
' Alex ' n2=n1*3print(n2)
>> output is Alexalexalex
2. Digital
Addition: +
Subtraction:-
Multiplication: *
Division:/
exponentiation: * *
Residual:% >> can be used to determine odd even
A = input ("' = a% 2if temp = = 0 :print (' C9>a is a evennumber ')else: print (' A is a odd number ')
Business://
Python conditional statements and basic data types