PYTHON教程之条件语句if判断

畅学网 Python评论419阅读模式

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管理、代码跳转、智能提示、自动完成、...

发表评论