for --loop
for number in list:
#do
start_list = [5, 3, 1, 2, 4] 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
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[k]
#A star of a popular children‘s cartoon show.
#Goes on the floor.
#A small amount.
#The sound a goat makes.remove的用法(删除特定元素)
a = [‘gg‘,‘tt‘,‘ty‘] a.remove(‘gg‘) print a #[‘tt‘,‘ty‘]
del的用法(删除index)
a = [‘gg‘,‘tt‘,‘ty‘] del a[1] print a #[‘tt‘,‘ty‘]
本文出自 “杨柳岸” 博客,请务必保留此出处http://jackzones.blog.51cto.com/5001676/1722947
原文:http://jackzones.blog.51cto.com/5001676/1722947