python入门-IF语句
2024-10-20 03:16:13
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语句格式
在 == >= <= 两边各加一个空格
最新文章
- 多线程同步工具——volatile变量
- Linux用户体系和文件权限总结
- ASP.NET杂谈-一切都从web.config说起(2)(ConfigSections详解-中)
- [转]SQL、LINQ、Lambda
- HDU 1253 胜利大逃亡(三维BFS)
- 第四章 Linux环境
- Django里面的RequestContext
- Springmvc+Spring+Hibernate搭建方法
- OpenStack/devstack with Neutron on Ubuntu 14 (2)
- C#基础:.NET环境下WebConfig的加密
- Java两种方法实现循环报数
- js多回调函数
- Java 基础之一对象导论
- kubernetes 创建nginx 容器
- Cracking The Coding Interview 5.7
- Unity 环境区域网格化
- Sagas模式
- Python学习笔记5-时间模块time/datetime
- 遍历页面上主从表中从table中的内容
- [转] #ifndef#define#endif的用法(整理) 原作者:icwk
热门文章
- EasyTouch中多种QuickGesture手势检测
- ElasticSearch(六):IK分词器的安装与使用IK分词器创建索引
- hot load那点事
- django 远程数据库mysql migrate失败报error 1045之 解决方案
- java并发编程-Executor框架 + Callable + Future
- benthos 通过配置文件配置 stream 说明
- 作为一名IT从业者,你在工作和学习中,遇到哪些问题
- mave安装配置
- 无人驾驶之激光雷达&;摄像头(主要from 速腾CEO 邱纯鑫分享)
- WPF ListView 简单的拖拽实现(转)