#!/user/bin/env python

cars = ['audi','bmw','subaru','toyota']
for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())

# == !=
# <= >=
# and or
# in not in
# True False
# if-else
# if-elif-elif-else # 选择一个执行
requesed_toppings = ['mushrooms','green peppers','extra cheese']
for requesed_topping in requesed_toppings:
if requesed_topping == 'green peppers':
print("Sorry,we are out of green peppers now.")
else:
print("Addin" + requesed_topping + ".")
print('\nFinished making your pizza!')

# 确定列表不是空
requesed_toppings = []
if requesed_toppings:
for requesed_topping in requesed_toppings:
print("Adding" + requesed_topping + ".")
print("\nFinished making your pizza!")
else:
print("Are you sure you want a plain pizza?")

python从入门到实践-5章if语句的更多相关文章

  1. python从入门到实践 第二章

    python变量赋值: python的变量赋值 可以是单引号 也可以是双引号python 变量赋值的时候不能加()的 比如 name = "My Name is GF"变量赋值的时 ...

  2. python从入门到实践-11章测试模块(测试函数出问题)

    #!/user/bin/env python# -*- coding:utf-8 -*- # 用python中unittes中工具来测试代码 # 1.测试函数import unittestfrom n ...

  3. python从入门到实践-10章文件和异常(括号问题)

    #!/user/bin/env python# -*- coding:utf-8 -*- # 1.从文件中读取数据with open('pi_digits.txt') as file_object: ...

  4. python从入门到实践-9章类

    #!/user/bin/env python# -*- coding:utf-8 -*- # 类名采用的是驼峰命名法,即将类名中每个单词的首字母大写,而不使用下划线.# 对于每个类,都应紧跟在类定义后 ...

  5. python从入门到实践-8章函数

    #!/user/bin/env python# -*- coding:utf-8 -*- # 给形参指定默认值时,等号两边不要有空格 def function_name("parameter ...

  6. python从入门到实践-7章用户输入和while循环

    #!/user/bin/env python# -*- coding:utf-8 -*- # input() 可以让程序暂停工作# int(input('please input something: ...

  7. python从入门到实践-6章字典

    #!/user/bin/env python# -*- coding:utf-8 -*- # 前面不用空格,后面空格# 访问只能通过keyalien_0 = {'color': 'green', 'p ...

  8. Python:从入门到实践--第九章-类--练习

    #.餐馆:创建一个名为Restaurant的类,其方法_init_()设置两个属性:restaurant_name和cuisine_type. #创建一个名为describe_restaurant的方 ...

  9. python从入门到实践-4章操作列表

    magicians = ['alice','david','carolina']for magician in magicians: print(magician) print(magician.ti ...

随机推荐

  1. expect 批量自动部署ssh 免密登陆 之 三

    #!/bin/expect -- ########################################## zhichao.hu #Push the id.pas.pub public k ...

  2. Django --- 单表的增删改查

  3. [Linux]fcntl函数文件锁概述

    概述 fcntl函数文件锁有几个比较容易忽视的地方: 1.文件锁是真的进程之间而言的,调用进程绝对不会被自己创建的锁锁住,因为F_SETLK和F_SETLKW命令总是替换调用进程现有的锁(若已存在), ...

  4. 工具篇之GIT知识整理(一)

    目录 项目工具篇(一)GIT 说在前面 背景 与其他版本控制产品对比 Git下载地址及安装 下载地址 安装 在案例中简单使用Git命令 git clone git log git diff git c ...

  5. WOW.js – 让页面滚动更有趣

    官网:http://mynameismatthieu.com/WOW/ 建议去官网一看 下载地址:https://github.com/matthieua/WOW 浏览器兼容 IE10+  Chrom ...

  6. cocos creator中粒子效果的使用

    就如同上图的星星特效一样,在触碰时产生特效,但是并不销毁节点,因为要使用很多次,因此使用节点池NodePool保存起来的. 以下是使用粒子效果使要使用到的一些基本控制函数: 我的使用:

  7. Python数据可视化之Matplotlib实现各种图表

    数据分析就是将数据以各种图表的形式展现给领导,供领导做决策用,因此熟练掌握饼图.柱状图.线图等图表制作是一个数据分析师必备的技能.Python有两个比较出色的图表制作框架,分别是Matplotlib和 ...

  8. hibernate-release-5.2.9.Final

    链接:https://pan.baidu.com/s/1UaoaaXb5C9gJp3Yu7sjUVQ 提取码:orgx

  9. linux学习之命令的排列、替换和别名--2019-04-23

    1.命令的排列 1)使用“;” 使用“;”命令时,不管命令1是否出错,接下来都执行命令2. 2)使用“&&” 使用“&&”命令时,只有命令1正确运行,接下来才会执行命令 ...

  10. python搭建opencv

    说明 windows下:以管理员身份使用cmd或者powershell. 安装 依次输入以下命令,安装numpy, Matplotlib, opencv三个包 pip install --upgrad ...