231312 发表于 2015-12-15 08:42:10

Python中的for循环,codecademy

for--loop

for number in list:
#do


1
2
3
4
5
6
7
start_list =
square_list = []

for n in start_list:
    square_list.append(n ** 2)
square_list.sort()
print square_list




list = array

dictionary = hash

dictionary = {'key1' : 1, 'key2' : 2 , 'key3' : 3}
dictionary for

1
2
3
4
5
6
7
8
9
10
11
12
13
webster = {
    "Aardvark" : "A star of a popular children's cartoon show.",
    "Baa" : "The sound a goat makes.",
    "Carpet": "Goes on the floor.",
    "Dab": "A small amount."
}
for k in webster:
    print webster
   
#A star of a popular children's cartoon show.
#Goes on the floor.
#A small amount.
#The sound a goat makes.





remove的用法(删除特定元素)

1
2
3
4
a = ['gg','tt','ty']
a.remove('gg')
print a
#['tt','ty']




del的用法(删除index)

1
2
3
4
a = ['gg','tt','ty']
del a
print a
#['tt','ty']



页: [1]
查看完整版本: Python中的for循环,codecademy