PYTHON教程之条件语句if判断

畅学网 Python评论325阅读模式

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

 

 
畅学网
  • 本文由 畅学网 发表于 2018年4月5日16:54:01
  • 转载请务必保留本文链接:https://51changxue.com/393.html
Python

pycharm永久破解激活教程

PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、...
Python

Tkinter控件快速引用总结

  文件名称: Tkinter控件快速引用总结代码.rar 文件大小: 4k 更新日期: 2018-7-29 文件版本: V1.0 免责声明: 本站大部分下载资源收集于网络,只做学习和交流使...
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证