Python的if语句
1、if-else语句
Tom_age = input('The age of Tom:' ) Mary_age = input('The age of Mary:') if Tom_age > Mary_age: print('Tom older than Mary.') else: print('Mary older than Tom.') #如果Tom和Mary的年龄一样大怎么办?
输出结果:
The age of Tom:15
The age of Mary:14
Tom older than Mary.
2、if-elif-else
Tom_age = input('The age of Tom:' ) Mary_age = input('The age of Mary:') if Tom_age > Mary_age: print('Tom older than Mary.') elif Tom_age == Mary_age: print('Mary is as old as Tom.') else: print('Tom younger than Mary.')
The age of Tom:11
The age of Mary:11
Mary is as old as Tom.