当前位置: 首页 > news >正文

广州网站制作哪家强龙岗网站建设公司哪家口碑好

广州网站制作哪家强,龙岗网站建设公司哪家口碑好,课题组网站怎么做,58同城西安网站建设CSDN 课程推荐#xff1a;《8小时Python零基础轻松入门》#xff0c;讲师齐伟#xff0c;苏州研途教育科技有限公司CTO#xff0c;苏州大学应用统计专业硕士生指导委员会委员#xff1b;已出版《跟老齐学Python#xff1a;轻松入门》《跟老齐学Python#xff1a;Django实… CSDN 课程推荐《8小时Python零基础轻松入门》讲师齐伟苏州研途教育科技有限公司CTO苏州大学应用统计专业硕士生指导委员会委员已出版《跟老齐学Python轻松入门》《跟老齐学PythonDjango实战》、《跟老齐学Python数据分析》和《Python大学实用教程》畅销图书。Python3 基础学习笔记第四章【if 语句】目录【4.1】一个简单的数列 【4.1.1】检查特定值是否包含在列表当中 【4.2】if-else 语句 【4.3】if-elif-else 结构 【4.3.1】使用多个 elif 代码块 【4.3.2】省略 else 代码块 【4.4】测试多个条件 【4.5】使用 if 语句处理列表 【4.5.1】检查特殊元素【4.5.2】确定列表不是空的【4.5.3】使用多个列表【4.1】一个简单的数列 给定一个汽车列表将其中每一辆汽车的名称打印出来要求打印 ‘bmw’ 时所有字母都要大写其余名称只需要首字母大写 cars [audi , bmw , subaru , toyota]for car in cars:if car bmw:print(car.upper())else:print(car.title())输出结果如下 Audi BMW Subaru Toyota【4.1.1】检查特定值是否包含在列表当中 要判断特定的值是否已包含在列表当中可使用关键字 in user_names [andia , david , liwa]user andiaif user in user_names:print(user.title() is in user_name.)输出结果如下 Andiais in user_name.要判断特定的值是否不包含在列表当中可使用关键字 not in user_names [andia , david , liwa]user kivleif user not in user_names:print(user.title() is not in user_name.)输出结果如下 Kivleis not in user_name.【4.2】if-else 语句 age input(请输入你的年龄查看是否可以去网吧)if int(age) 18:print(You are old enough to go to the net bar!)print(You should go to net bar less,study more!)else:print(You are too young to go to the net bar!)print(Wait until you are 18 to go to the net bar!)分别输入19和15输出结果如下 请输入你的年龄查看是否可以去网吧19You are old enough to go to the net bar!You should go to net bar less,study more!请输入你的年龄查看是否可以去网吧15You are too young to go to the net bar!Wait until you are 18 to go to the net bar!【4.3】if-elif-else 结构 age 12if age 4:price 0elif age 18:price 5else:price 10print(Your admission cost is $ str(price) .)输出结果如下 Your admission cost is $5.【4.3.1】使用多个 elif 代码块 age 20 if age 4:price 0 elif age 18:price 5 elif age 65:price 15 else:price 10 print(Your admission cost is $ str(price) .)输出结果如下 Your admission cost is $15.【4.3.2】省略 else 代码块 Python并不要求 if-elif 结构后面必须有 else 代码块 age 20 if age 4:price 0 elif age 18:price 5 elif age 65:price 15 elif age 65:price 10 print(Your admission cost is $ str(price) .)输出结果仍与3.3.1一样 【4.4】测试多个条件 if-elif-else结构功能强大但仅适用于只有一个条件满足的情况遇到通过了的测试后Python就会跳过余下的测试 names [Zhangshan , Wanger] if Zhangshan in names:print(Zhangshan is here!) if Wanger in names:print(Wanger is here!) if Xiaoming in names:print(Xiaoming is here!) print(All the students are here!)输出结果如下 Zhangshan is here! Wanger is here! All the students are here!相同的程序如果使用 if-elif-else 结构代码将不能正确运行 names [Zhangshan , Wanger] if Zhangshan in names:print(Zhangshan is here!) elif Wanger in names:print(Wanger is here!) elif Xiaoming in names:print(Xiaoming is here!) print(All the students are here!)输出结果如下 Zhangshan is here! All the students are here!总之如果我们只想执行一个代码块就使用 if-elif-else 结构如果要运行多个代码块就必须使用一系列独立的 if 语句 【4.5】使用 if 语句处理列表 【4.5.1】检查特殊元素 对3.4例子改版加入姓名 ‘Xiaoming’当检索到Xiaoming时告诉他他妈妈叫他回家吃饭 names [Zhangshan , Wanger , Xiaoming] for name in names:if name Xiaoming:print(Xiaoming,Your mother told you to go home for dinner!)else:print(name is here!) print(All the students are here!)输出结果如下 Zhangshanis here! Wangeris here! Xiaoming,Your mother told you to go home for dinner! All the students are here!【4.5.2】确定列表不是空的 在检索姓名前检查姓名是否为空不为空则打印出所有姓名为空则提示没有姓名 names [] if names:for name in names:print(name is here!)print(All the students are here!) else:print(There is no students!)输出结果如下 There is no students!在if语句中将列表名用在条件表达式中时Python将在列表至少包含一个元素时返回Ture并在列表为空时返回False 【4.5.3】使用多个列表 两个列表names_1和names_2要求输出既在names_2中又在names_1中的元素 names_1 [Zhangshan , Liyang , Wanger , Tangyang , Xiaoming] names_2 [Liyang , Zhangwei , Tangyang] for names in names_2:if names in names_1:print(names is here!) print(All the students are here!)输出结果如下 Liyang is here! Tangyang is here! All the students are here!
http://www.zqtcl.cn/news/765966/

相关文章:

  • 做公司网站的尺寸一般是多大无障碍浏览网站怎么做
  • 网站登陆界面psd手机一元云购网站建设
  • 网站规范化建设wordpress iis7.5 伪静态
  • 济南网站设计建设公司深圳seo外包公司
  • 重庆信息网站推广网站做推广如何设计二维码
  • 学历低的人不适合学编程小红书seo关键词优化多少钱
  • pc网站制作公司企业邮箱格式模板
  • 河南5G网站基站建设信息wordpress自定义文章页面模板下载
  • 宁波三优互动网站建设公司怎么样手机app商城
  • 散热器 东莞网站建设php模板源码
  • 怎么申请域名建网站凡科网站建设总结
  • 温州网站设计定制外贸人才网哪家最好
  • 永康门业微网站建设做一个网站要多长时间
  • 南山网站建设哪家好四川省微信网站建设公
  • 网件路由器做网站网站建设中 提示
  • 全运网站的建设徐州网络推广公司排名
  • 成品网站源码1688体验区南宁网络推广服务商
  • 广州品牌网站开发公司网站建设价位
  • 网站首页没排名但内页有排名wordpress网站收录插件
  • 在线相册jsp网站开发与设计微信小程序app下载
  • 广元市建设局网站首页网站建设首选公司哪家好
  • 商务网站建设策划思路平台网站如何做推广方案设计
  • 哈尔滨网站快速排名通辽网站建设
  • 雄安专业网站建设哪家好分销系统网站建设
  • 咨询行业网站开发wordpress5.0新版如何发布文章
  • 做网站要什么技术saas建站和开源建站的区别
  • 大型网站建设哪家服务好qq对话制作器app
  • 做免费小说网站怎样赚钱网络推广方案最新
  • 电商网站的建设与运营揭阳专业的网站建设价格
  • 网站策划书包括哪些内容百度官方营销推广平台有哪些