5-2str = 'Hello'
if str == 'Hello':
print('str = Hello')
if str != '123':
print('str != 123')
if str.lower() == 'hello':
print('str.lower() = hello')
if(1 == 2-1):
print('1==1')
if 1!=2:
print('1!=2')
if 1<2:
print('1<2')
if 2>1:
print('2>1')
if 2>=1:
print('2>=1')
if 1<=2:
print('1<=2')
if 1<2 and 2<3:
print('1<2<3')
if 1<2 or False:
print('1<2')
numbers = range(1,10)
if 10 not in numbers:
print('10 not in range(1,10)')
if 3 in range(1,10):
print('3 in range(1,10)')
5-7favorite_fruits = ['apple','pear','grape']
if 'apple' in favorite_fruits:
print('You really like bananas!')
if 'pear' in favorite_fruits:
print('You really like bananas!')
if 'grape' in favorite_fruits:
print('You really like bananas!')
if 'banana' in favorite_fruits:
print('You really like bananas!')
if 'watermelon' in favorite_fruits:
print('You really like bananas!')
5-11for i in range(1,10):
flag = 'th'
if i==1:
flag = 'st'
elif i==2:
flag = 'nd'
elif i==3:
flag = 'rd'
print(str(i)+flag)
5-12:5-11的审核后的代码for i in range(1,10):
flag = 'th'
if i == 1:
flag = 'st'
elif i == 2:
flag = 'nd'
elif i == 3:
flag = 'rd'
print(str(i) + flag)