#if语句
names = ['tom','tony','lili','dave']
for name in names:		#当检查姓名为lili时,全大写打印,否则以首字母大写打印
	if name == 'lili':
		print(name.upper())
	else:
		print(name.title())
print("----------------------")

#条件测试
name1 = 'Dave'
name2 = 'Tom'
if name1.lower() == 'dave' and name2 == 'Tom':		#使用and和or检查多个条件
	print("true")
if name1.lower() == 'Dave' or name2 == 'Tom':
	print("true")
print("----------------------")

#if-else语句
age = 18
if age > 18:
	print("you are too old!")
else:
	print("you are so little!")
print("----------------------")

#if-elif-else语句,多个elif同理,else可以省略
age = 12
if age < 12:
	print("you can get $100")
elif age == 12:
	print("you can get $80")
else:
 	print("you can get $50")
print("----------------------")

#多个测试条件
names3 = ['1','2','3','4']
if '1' in names3:
	print("1 in")
if '5' in names3:
	print("5 in")	
if '3' in names3:
	print("3 in")

打印结果:

Tom
Tony
LILI
Dave
----------------------
true
true
----------------------
you are so little!
----------------------
you can get $80
----------------------
1 in
3 in