博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
笨办法32循环和列表
阅读量:7223 次
发布时间:2019-06-29

本文共 898 字,大约阅读时间需要 2 分钟。

代码如下:

1 fruits = ['apples', 'oranges', 'pears', 'apricots'] 2 change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] 3  4 # this first kind of for-loop goes through a list 5 for number in the_count: 6     print "This is count %d" % number 7  8 # same as above 9 for fruit in fruits:10     print "A fruit of type: %s" % fruit11 12 # also we can go through mixed lists too13 # notice we have to use %r since we don't know what's in it14 for i in change:15     print "I got %r" % i16 17 # we can also build lists, first start with an empty one18 elements = []19 20 # then use the range function to do 0 to 5 counts21 for i in range(0, 6):22     print "Adding %d to the list." % i23     # append is a function that lists understand24     elements.append(i)25 26 # now we can print them out too27 for i in elements:28     print "Element was: %d" % i

运行结果:

 

转载于:https://www.cnblogs.com/p36606jp/p/8088389.html

你可能感兴趣的文章
简洁JS 日历控件 支持日期和月份选择
查看>>
游戏领域区块链探索
查看>>
AQS 实现分析
查看>>
开发者必备:软件功能规格书的重要性
查看>>
在flask-sqlalchemy中使用分页
查看>>
Java 类库 URI 与 URL 的区别和联系
查看>>
解压缩命令
查看>>
指针的引用——在函数中的巧妙应用
查看>>
IOS上路_06-简单示例-播录声音
查看>>
Win8 X64安装virtualbox + centos X64问题
查看>>
Windows 安装 MongoDB 的 zip 版本
查看>>
CORS(跨域资源共享) 的配置
查看>>
Groovy&Grails-代码剪辑-对象关系
查看>>
JavaScript函数中的arguments对象
查看>>
杭电2032
查看>>
xcode 6.3 导入文件夹,没有创建组
查看>>
Android开发入门教程(八):重新创建Activity
查看>>
Tomcat 7.0.63启动报错
查看>>
MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables
查看>>
密码技术四 分组密码的模式
查看>>