3-1
names = ['day', 'lxd', 'wzy', 'zzz']
print(names[0])
print(names[1])
print(names[2])
print(names[3])
易错 :[]与()是两种格式,一个是tuple,一个是list
?3-2
names = ['day', 'lxd', 'wzy', 'zzz']
print(f"{names[0]},nice to meet you ")
print(f"{names[1]},nice to meet you ")
print(f"{names[2]},nice to meet you ")
print(f"{names[3]},nice to meet you ")
3-3
cars = ['honda', 'byd', 'bwm', 'zzz']
print(f"I would like to own a {cars[0]} car.")
print(f"I would like to own a {cars[1]} car.")
print(f"I would like to own a {cars[2]} car.")
print(f"I would like to own a {cars[3]} car.")
3-4
names = ['day', 'lxd', 'wzy', 'zzz']
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.")
3-5
names = ['day', 'lxd', 'wzy', 'zzz']
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.\n")
print(f"{names[0]} can't come.\n")
del(names[0])
names.append('zyf')
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.")
3-6
names = ['day', 'lxd', 'wzy', 'zzz']
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.\n")
print(f"{names[0]} can't come.\n")
del(names[0])
names.append('zyf')
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.\n")
print("find more bigger desk\n")
names.insert(0, 'zcy')
names.insert(2, 'sk')
names.append('dq')
for name in names:
print(f"{name},I want to invite you to have dinner with me.")
3-7
names = ['day', 'lxd', 'wzy', 'zzz']
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.\n")
print(f"{names[0]} can't come.\n")
del(names[0])
names.append('zyf')
print(f"{names[0]},I want to invite you to have dinner with me.")
print(f"{names[1]},I want to invite you to have dinner with me.")
print(f"{names[2]},I want to invite you to have dinner with me.")
print(f"{names[3]},I want to invite you to have dinner with me.\n")
print("find more bigger desk\n")
names.insert(0, 'zcy')
names.insert(2, 'sk')
names.append('dq')
for name in names:
print(f"{name},I want to invite you to have dinner with me.")
print("sorry ,i can only invite two people.")
ch = names.pop(-1)
print(f"{ch},sorry,i can't invite you.")
ch = names.pop(-1)
print(f"{ch},sorry,i can't invite you.")
ch = names.pop(-1)
print(f"{ch},sorry,i can't invite you.")
ch = names.pop(-1)
print(f"{ch},sorry,i can't invite you.")
ch = names.pop(-1)
print(f"{ch},sorry,i can't invite you.\n")
print(f"{names[0]},i invite you to have dinner.")
print(f"{names[1]},i invite you to have dinner.")
del names[0]
del names[0]
#删除一个元素后列表只有一个元素,如果names[1]将报错
print(names)
易错:删除一个元素后列表只有一个元素,如果names[1]将报错
3-8
places = ['america', 'china', 'japan', 'iyaly', 'france']
print(sorted(places))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse=True)
print(places)
?3-9
names = ['day', 'lxd', 'wzy', 'zzz']
print(len(names))
names.insert(0, 'zcy')
names.insert(2, 'sk')
names.append('dq')
print(len(names))
3-10
?
games = ['lol', 'csgo', 'rust', 'lor']
print(games)
print(f"{games[0]},I think it is best game.")
print(f"{games[1]},I think it is best game.")
del(games[0])
games.append('coh')
games.remove('rust')
games.pop()
games.insert(0, 'dayz')
games.insert(3, 'cf')
games.append('lis')
print(len(games))
print(sorted(games))
games.sort()
print(games)
games.sort(reverse=True)
games.reverse()
?
|