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(' ') # 讲 ten_things 的元素分开, 并将分开之后的元素创建成 数组
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"]
while len(stuff) != 10: # len 函数可以测算 数组的长度
next_one = more_stuff.pop()
print("Adding: ", next_one)
stuff.append(next_one)
print("There's {0} items now.".format(len(stuff)))
print("There we go: ", stuff)
print("Let's do some things with stuff.")
print(stuff[1])
print(stuff[-1])
print(stuff.pop()) # pop() = pop(-1)
print(" ".join(stuff)) # 使用空格连接stuff的内容
print("#".join(stuff[3:5])) # 使用 # 连接 stuff 的内容
笨方法学Python 习题38
最新推荐文章于 2023-02-13 23:09:35 发布