||
1, If statements
if condition:
xxxx
Example:
name='alibaba'
if name=='alibaba':
print('My name is alibaba')
2, else statements
Example:
name='alibaba'
if name=='alibaba':
print('My name is alibaba')
else:
print('Who are you?')
3, elif statements (= else if)
age=20
if age<15:
print('You are young')
elif age<30:
print('You are junior')
elif age<50:
print('Your are senior')
else:
print('You are old')
Keep in mind: not forget the ":" after the definition of a condition
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-19 20:55
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社