程序源码

ten_things = "Apples Orange Crows Telephone Light Sugar" 

print("Wait there are not 10 things in that list. Let's fix that.")

stuff = ten_things.split(' ')

more_stuff = ["Day","Night","Song","Frisbee","Corn","Banana","Gril","Boy"]


while len(stuff) != 10:
    next_one = more_stuff.pop() #去列表最后一个元素
    print(repr(more_stuff))
    print("Adding: ", next_one)
    stuff.append(next_one)
    print(f"There are {len(stuff)} items now.")


print("There we go: ", stuff)

print("Let's do some things with stuff.")

print(stuff[1])
print(stuff[-1]) # whoa! fancy
print(stuff.pop())
print(' '.join(stuff)) # what? cool!
print('#'.join(stuff[3:5])) # super stellar!

输出结果

Wait there are not 10 things in that list. Let's fix that.
['Day', 'Night', 'Song', 'Frisbee', 'Corn', 'Banana', 'Gril']      
Adding:  Boy
There are 7 items now.
['Day', 'Night', 'Song', 'Frisbee', 'Corn', 'Banana']
Adding:  Gril
There are 8 items now.
['Day', 'Night', 'Song', 'Frisbee', 'Corn']
Adding:  Banana
There are 9 items now.
['Day', 'Night', 'Song', 'Frisbee']
Adding:  Corn
There are 10 items now.
There we go:  ['Apples', 'Orange', 'Crows', 'Telephone', 'Light', 'Sugar', 'Boy', 'Gril', 'Banana', 'Corn']
Let's do some things with stuff.
Orange
Corn
Corn
Apples Orange Crows Telephone Light Sugar Boy Gril Banana
Telephone#Light
最后修改:2022 年 09 月 05 日
如果觉得我的文章对你有用,请随意赞赏