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

营销型网站五大系统 单仁网站做接口到app价格

营销型网站五大系统 单仁,网站做接口到app价格,品牌策划咨询,成都网站建设设计公司文章目录 一. 遍历整个列表1. 在for循环中执行更多操作2. 在for循环结束后执行一些操作 二. 避免缩进错误三. 创建数值列表1. 使用函数range()2. 使用range()创建数字列表3. 指定步长。4. 对数字列表执行简单的统计计算5. 列表解析 五. 使用列表的一部分-切片1. 切片2. 遍历切片… 文章目录 一. 遍历整个列表1. 在for循环中执行更多操作2. 在for循环结束后执行一些操作 二. 避免缩进错误三. 创建数值列表1. 使用函数range()2. 使用range()创建数字列表3. 指定步长。4. 对数字列表执行简单的统计计算5. 列表解析 五. 使用列表的一部分-切片1. 切片2. 遍历切片3. 复制列表浅拷贝与深拷贝4. 元组 一. 遍历整个列表 if __name__ __main__:magicians [alice, david, carolina]for magician in magicians:print(magician)1. 在for循环中执行更多操作 if __name__ __main__:magicians [alice, david, carolina]for magician in magicians:print(f{magician.title()}, that was a great trick) 2. 在for循环结束后执行一些操作 在for循环后面没有缩进的代码都只执行一次不会重复执行。 if __name__ __main__:magicians [alice, david, carolina]for magician in magicians:print(f{magician.title()}, that was a great trick)print(Thank you。)二. 避免缩进错误 Python根据缩进来判断代码行与前一个代码行的关系。 简单地说它要求你使用缩进让代码整洁而结构清晰。在较长的Python程序中你将看到缩进程度各不相同的代码块从而对程序的组织结构有大致的认识。 下面来看一些较为常见的缩进错误。 忘记缩进 对于位于for语句后面且属于循环组成部分的代码行一定要缩进。 忘记缩进额外的代码行: magicians [alice, david, carolina]for magician in magicians:print(f{magician.title()}, that was a great trick!)print(fI cant wait to see your next trick, {magician.title()}.\n) # 也需要进行缩进不必要的缩进 函数调用print()见❶无须缩进因为它并非循环的组成部分。 message Hello Python world! ❶ print(message)遗漏了冒号 for语句末尾的冒号告诉Python下一行是循环的第一行。 magicians [alice, david, carolina] ❶ for magician in magiciansprint(magician)如果不小心遗漏了冒号如❶所示将导致语法错误因为Python不知道你意欲何为。 三. 创建数值列表 1. 使用函数range() for value in range(1, 5):print(value)它不会打印5只有1到4。 2. 使用range()创建数字列表 要创建数字列表可使用函数list()将range()的结果直接转换为列表。 numbers list(range(1, 6)) print(numbers)3. 指定步长。 为此可给这个函数指定第三个参数看一个例子 打印110的偶数 even_numbers list(range(2, 11, 2)) print(even_numbers)创建一个列表其中包含前10个整数110的平方 squares []for value in range(1,11): ❶ squares.append(value**2)print(squares)4. 对数字列表执行简单的统计计算 最小、最大、总和。 digits [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]min(digits) 0max(digits) 9sum(digits) 45本节使用的数字列表都很短但这里介绍的知识也适用于包含数百万个数的列表。 5. 列表解析 列表解析将for循环和创建新元素的代码合并成一行并自动附加新元素 squares [value**2 for value in range(1, 11)] print(squares)五. 使用列表的一部分-切片 处理列表的部分元素Python称之为切片。 1. 切片 要创建切片可指定要使用的第一个元素和最后一个元素的索引。与函数range()一样Python在到达第二个索引之前的元素后停止。 players [charles, martina, michael, florence, eli] ❶ print(players[0:3])# [charles, martina, michael]如果没有指定第一个索引Python将自动从列表开头开始 players [charles, martina, michael, florence, eli] print(players[:4])如果要提取从第三个元素到列表末尾的所有元素可将起始索引指定为2并省略终止索引 players [charles, martina, michael, florence, eli] print(players[2:])如果要输出名单上的最后三名队员可使用切片players[-3:] players [charles, martina, michael, florence, eli] print(players[-3:])2. 遍历切片 遍历前三名队员并打印他们的名字 players [charles, martina, michael, florence, eli]print(Here are the first three players on my team:) ❶ for player in players[:3]:print(player.title())3. 复制列表浅拷贝与深拷贝 要复制列表可创建一个包含整个列表的切片方法是同时省略起始索引和终止索引[:]。 ❶ my_foods [pizza, falafel, carrot cake] ❷ friend_foods my_foods[:]print(My favorite foods are:)print(my_foods)print(\nMy friends favorite foods are:)print(friend_foods)如果只是将my_foods赋给friend_foods就不能得到两个列表。 my_foods [pizza, falafel, carrot cake]# 这行不通: ❶ friend_foods my_foodsmy_foods.append(cannoli)friend_foods.append(ice cream)print(My favorite foods are:)print(my_foods)print(\nMy friends favorite foods are:)print(friend_foods)# My favorite foods are: # [pizza, falafel, carrot cake, cannoli, ice cream]# My friends favorite foods are: # [pizza, falafel, carrot cake, cannoli, ice cream]这种语法实际上是让Python将新变量friend_foods关联到已与my_foods相关联的列表因此这两个变量指向同一个列表。类似于浅拷贝。 4. 元组 Python将不能修改的值称为不可变的而不可变的列表被称为元组。 定义元组 元组看起来很像列表但使用圆括号而非中括号来标识。 定义元组后就可使用索引来访问其元素就像访问列表元素一样。 ❶ dimensions (200, 50) ❷ print(dimensions[0])print(dimensions[1])dimensions (200, 50) for dimension in dimensions:print(dimension)虽然不能修改元组的元素但可以给存储元组的变量赋值。因此如果要修改前述矩形的尺寸可重新定义整个元组 ❶ dimensions (200, 50)print(Original dimensions:)for dimension in dimensions:print(dimension)❷ dimensions (400, 100) ❸ print(\nModified dimensions:)for dimension in dimensions:print(dimension)如果需要存储的一组值在程序的整个生命周期内都不变就可以使用元组。 参考《Python编程从入门到实践第二版》
http://www.hkea.cn/news/14459951/

相关文章:

  • 中国信誉建设网站怎么做网站弹出公告
  • 深圳市宝安网站建设大连筑成建设集团有限公司网站
  • 重庆没建网站的企业厦门专业网站设计公司
  • 做旅游网站怎么融资网站开发买什么书
  • 做内部优惠券网站秦皇岛的网站建设公司
  • 网站建设需要几步建设银行网站机构
  • 定制网站本地企业小程序定制开发公司
  • 政务内网网站群建设seo网站优化详解
  • 个人房产信息查询网站东莞龙舟制作技艺
  • 企业网站的宣传功能体现在()巴南城乡建设网站
  • 教做蛋糕的网站网站 建设 现状
  • 网站建设详细工作汇报网络营销顾问是干嘛的
  • 电子图书网站开发的目的青岛简易付网络技术有限公司
  • 做检测设备的网站有哪些WordPress站内链接设置
  • 三亚网站开发公司十堰新闻
  • 江苏省城乡与建设厅网站首页广州小程序制作开发
  • 呼和浩特整站优化网站设计配色
  • 有什么专门做电子琴音乐的网站贵阳小程序开发
  • 做网站的app有什么作用怀化网站优化
  • 网站开发php技术汉字logo标志设计
  • 网站建设的实训报告怎么写展示网站建设
  • 涿州网站建设公司有哪些服务之家网站推广
  • 怎样让公司网站更吸引人wordpress安装后设置
  • seo收录排名网站优化月总结
  • 公司网站备案电话做jsp网站用哪些软件下载
  • 网站建设设计12355能找回智慧团建密码吗
  • 青岛中企动力做网站怎么样哪里可以建网站
  • 做采集网站赚钱吗应用镜像 wordpress
  • 完整域名展示网站源码做网站 找风投
  • 永久网站建设广州网站建设支付