ten_things = "Apples Oranges Crows Telephone Light Sugar"
print("Wait there's not 10 things in that list, let's fix that.")
# 将字符串按空格分开为列表str.split(' ')
stuff = ten_things.split(' ')
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "boy"]
while len(stuff) != 10:
# 弹出最后一个元素
next_one = more_stuff.pop()
print("Adding:",next_one)
# 添加一个元素
stuff.append(next_one)
print("There's %d items now." % len(stuff))
print("There we go: ",stuff)
print("Let's do some thing with stuff.")
print(stuff[1])
print(stuff[-1])
print(stuff.pop())
# 将列表stuff以空格连为一个字符串
print(' '.join(stuff))
# 将列表stuff第4、第5个元素以空格连为一个字符串
print('#'.join(stuff[3:5]))
ex38——列表的操作
最新推荐文章于 2024-11-02 16:28:26 发布