检查相等和不等

多个检查条件

age1 = 22
age2 = 19
s1 = age1 > 21 and age2 > 19
print(s1)
s2 = age1 > 21 or age2 > 19
print(s2)

检查是否包含在列表内

requested_toppings = ['mushrooms','onions','pineapple']
s1 = 'mushrooms' in requested_toppings
print(s1)
s2 = 'pepperoni' in requested_toppings
print(s2)

检查不包含

requested_toppings = ['mushrooms','onions','pineapple']
s1 = 'mushrooms' not in requested_toppings
print(s1)
s2 = 'pepperoni' not in requested_toppings
print(s2)

if语句

age = 19
if age >= 18:
print('You are old enough to vote')
if age >= 20:
print('is no print')

if-elif-else语句

age = 12
if age < 4:
price = 0
elif age < 18:
price = 5
elif age < 65:
price = 10
else:
price = 5
print('Your admission cost is $' + str(price) + '.')

检查特殊元素

requested_toppings= ['mushrooms','green peppers','extra cheese']
for requested_topping in requested_toppings:
if requested_topping == 'green peppers':
print('Sorry,we are out of green peppers right now')
else:
print('Adding' + requested_topping + '.')

requested_toppings= []
if requested_toppings:
for requested_topping in requested_toppings:
print('Adding ' + requested_topping + '.')
else:
print('Are you sure you want a plain pizza?')

available_toppings = ['mushrooms','olives','green peppers','pepperoni']
requested_toppings= ['mushrooms','french fries','green peppers'] for requested_topping in requested_toppings:
if requested_topping in available_toppings:
print('Adding ' + requested_topping + '.')
else:
print("Sorry,we don\'t have " + requested_topping + '.')

最新文章

  1. EF 资料
  2. python抓取某学院视频
  3. 【BZOJ-4281】Związek Harcerstwa Bajtockiego 树上倍增LCA
  4. 【原】iOS学习40网络之数据安全
  5. 使用adb shell dumpsys检测Android的Activity任务栈
  6. javascript学习-原生javascript的小特效(改变透明度效果)
  7. in 与 = 的区别
  8. MVC4 Razor视图下使用iframe加载RDLC报表
  9. linux 定时执行shell脚本
  10. MySQL5.5.28启动错误 The server quit without updating PID file
  11. SDWebImage源码解读之SDWebImageManager
  12. 如何修改Tomcat默认端口?
  13. centos7 python3 pip
  14. Oracle下查看索引的语句
  15. 网球pt站 T3nnis 情况说明
  16. Android应用开发资源
  17. Ext Js 6+ 如何引入dashboard模版
  18. 路由交换02-----ARP协议
  19. Linux内核分析第四周学习总结
  20. oracle-sql分析练习

热门文章

  1. Redis基础(二)数据库
  2. 给大家分享一下java数据库操作步骤
  3. 如何将Docker升级到最新版本
  4. django JsonResponse返回中文时显示unicode编码(\u67e5\u8be2)
  5. yython爬虫基础知识入门
  6. uniapp微信小程序canvas隐藏
  7. logback日志打印sql
  8. 使用pipenv管理python虚拟环境
  9. yum针对软件包操作的常用命令
  10. exec 家族库函数以及系统调用(execl,execle,execlp and execv,execvp,execve)