# 《笨办法学Python》 第32课手记

### 《笨办法学Python》 第32课手记

```the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennise', 2, 'dimes', 3, 'quarters']

# this first kind of for-loop goes through a list
for number in the_count:
print "This is the_count %d" % number

# same as above
for fruit in fruits:
print "A fruit of type: %s" % fruit

# also we can go through mixed lists too
# notice we have to use %r since we don't know what's in it
for i in change:
print "I got %r" %i

# we can also build lists, first start with an empty one
elements = []

# then use the range function to do 0 to 5 counts
for i in range(0, 6):
print "Adding %d to the list." % i
# append is a function that lists understand
elements.append(i)

# now we can print them out too
for i in elements:
print "Element was: %d" % i```

i in range(0, 6)表示 i大于0小于6,该语句是循环控制语句，表示执行for循环的条件，满足就执行下面的语句，不满足该条件即跳出循环结束操作。

change = [1, ‘pennise’, 2, ‘dimes’, 3, ‘quarters’]，list可以数值和字符混合赋值，但输出是只能是一种格式。 print “I got %r” %i 该课中作者是以字符型数据输出的。

### 本节课涉及的知识

for循环：

```for judgement:
sentence1
sentence2
...```

256 篇文章52 人订阅

0 条评论

## 相关文章

34960

### Python 数据类型

Python主要数据类型包括list（列表）、tuple（元组）、dict（字典）和set（集合）等对象，下面逐一介绍这些Python数据类型。

9000

9310

12230

38970

30070

18640

### CC++变参函数

C语言中，有时需要变参函数来完成特殊的功能，比如C标准库函数printf()和scanf()。C中提供了省略符“…”能够帮主programmer完成变参函数的书...

9710

### Spring 学习笔记（七）—— 切入点表达式

语法结构：   execution(   方法修饰符  方法返回值  方法所属类 匹配方法名 (  方法中的形参表 )  方法申明抛出的异常  )

6010

314110