1. IF statement
if 1 == 1:
print('You got it right' )
else:
print('You answered wrong')
if 1 == 1:
print('You got it right')
print('You answered wrong')
IF double nesting:
if 1 == 1:
if 2 == 2
print('You got it right')
else:
print('stupid')
else: print('You answered wrong')
IF combined with input syntax:
didian = input('Please enter your location')
if didian == "Kindergarten":
print('Welcome to the bus')
else:
print('Roll')
The use of ELIF (multi-conditional judgment):
didian = input('Please enter your location:')
if didian == "Kindergarten":
print('Platform 1')
elif didian == "School":
print('Platform 2')
elif didian == 'Hometown':
print('Platform 3')
else:
print('Not within our service scope')
print('Start starting...')
The use of PASS and IF:
if 1 == 1:
pass
else:
print ('sb')
Note: There are four spaces in the TAB key to indicate that the code block below belongs to the above clause, double equals sign == , remember to add a colon after the condition:, pay attention to the usage of PASS (do nothing, do not execute )
2. Basic data types
String (quotes): name = 'Hehe Da'
Addition: n1 = "I" n2 = 'Yes' n3 = "SB" n4 = n1 + n2 +n3 = "I am SB"
Multiplication: n1 = "i" n2 = n1 * 10
Numbers: n1 = 10 n2 = 5 n3= n1 + n2 = 15 (**Double asterisks represent powers, % percent signs represent remainders, //Double bars take integer divisors (numbers before the decimal point)