PYTHON教程之条件语句if判断

2018年4月5日16:54:01 发表评论 248 views

PYTHON教程之条件语句if判断

PYTHON教程之条件语句if判断

#条件语句if语句
#if conditional_test:
#  do something
age=16
if age==16:
    print(age)
#if-else语句
#if conditional_test:
#   do something
#else:
#   do otherthing
if age>20:
    print("Age is older than 20!")
else:
    print("Age is not older than 20!")
#if-elif-else语句
#if conditional_test:
#   do something
#elif:
#   do otherthing
#else:
#   do  anotherthing
if age>20:
    print("Age is older than 20!")
elif age>18:
    print("Age is  older than 18 but younger than 20!")
else:
    print("Age is not older than 18!")

运行结果:

"D:\Program Files\python\python.exe" "D:/Program Files/python/example/PYTHON教程之条件语句if判断.py"
16
Age is not older than 20!
Age is not older than 18!

Process finished with exit code 0

 

51changxue

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: