リストの操作、練習問題38、learn python the hard way.
2461 ワード
]```
#coding=utf-8
ten_things = "Apples oranges Crows Telephone Light Sugar"
print "Wait there's not 10 things in that list, let's fix that."
stuff = ten_things.split(' ') #str.split(' ', num) num 。split() 。
more_stuff = ["Day", "Night", "Song", "Friebee", "Corn", "Banana", "Girl", "Boy"]
# ,
while len(stuff) != 10:
next_one = more_stuff.pop() # , more_stuff next_one, next_one stuff
print "Adding:", next_one
stuff.append(next_one)
print "There's %d items now." % len(stuff) #len
print "There we go:", stuff
print "Let's do something with stuff"
print stuff[1] # 1
print stuff[-1] #0 , :-1 。
print stuff.pop() # ,
print ' '.join(stuff) #
print '#'.join(stuff[3:5]) # #
“`