1 格式

cars = ['audi','bmw','subaru','toyata']

for car in cars:
if car =='bmw':
print(car.upper())
else:
print(car.title())

python检查相等的时候区分大小写

2 检查是否相等

car='bmw'
car=='bmw'

检查不相等

requested_topping='mushrooms'

if requested_topping !='anchovies':
print('hold the anchovies!')

3 多个条件 and  or

age_0=
age_1= if age_0>= and age_1>=:
print('ok')
else:
print('not ok')

4 检查特定的值 是否在列表中  in   not in

requested_toppings=['mushrooms','onions','pineapple']

'mushrooms' in requested_toppings
'mushrooms' not in requested_toppings

5 IF语句

if condition:

  do somthing

age=
if age>=:
print('is ok')
print('this is second ok')

6 if-else语句

age=
if age>=:
print('first is ok')
print('second is ok')
else:
print('third is ok')
print('fourth is ok')

7 if-elif-else 结构

age=
if age<:
print('your admission cost is $0')
elif age<:
print('your admission cost is #5')
else:
print('your adminssion cost is #10')

8 多个elif语句

age=
if age<:
price=
elif age<:
price=
elif age<:
price=
else:
price= print(price)

9 确认列表是不是空的

requested_toppings=[]
if requested_toppings:
for requested_topping in requested_toppings:
print('adding'+requested_topping+".")
print("\n finished making your pizza!")
else:
print('are you sure you want a plain pizza')

10 IF语句格式

在  ==  >= <= 两边各加一个空格

最新文章

  1. 多线程同步工具——volatile变量
  2. Linux用户体系和文件权限总结
  3. ASP.NET杂谈-一切都从web.config说起(2)(ConfigSections详解-中)
  4. [转]SQL、LINQ、Lambda
  5. HDU 1253 胜利大逃亡(三维BFS)
  6. 第四章 Linux环境
  7. Django里面的RequestContext
  8. Springmvc+Spring+Hibernate搭建方法
  9. OpenStack/devstack with Neutron on Ubuntu 14 (2)
  10. C#基础:.NET环境下WebConfig的加密
  11. Java两种方法实现循环报数
  12. js多回调函数
  13. Java 基础之一对象导论
  14. kubernetes 创建nginx 容器
  15. Cracking The Coding Interview 5.7
  16. Unity 环境区域网格化
  17. Sagas模式
  18. Python学习笔记5-时间模块time/datetime
  19. 遍历页面上主从表中从table中的内容
  20. [转] #ifndef#define#endif的用法(整理) 原作者:icwk

热门文章

  1. EasyTouch中多种QuickGesture手势检测
  2. ElasticSearch(六):IK分词器的安装与使用IK分词器创建索引
  3. hot load那点事
  4. django 远程数据库mysql migrate失败报error 1045之 解决方案
  5. java并发编程-Executor框架 + Callable + Future
  6. benthos 通过配置文件配置 stream 说明
  7. 作为一名IT从业者,你在工作和学习中,遇到哪些问题
  8. mave安装配置
  9. 无人驾驶之激光雷达&amp;摄像头(主要from 速腾CEO 邱纯鑫分享)
  10. WPF ListView 简单的拖拽实现(转)