Python中的for循环,codecademy
for--loopfor 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]