3-1姓名
names=['mike','kiki','sure','bob']
print(names[0])
print(names[1])
print(names[2])
print(names[3])
3-2问候语
names=['mike','kiki','sure','bob']
print(names[0]+', hello')
print(names[1]+', hello')
print(names[2]+', hello')
print(names[3]+', hello')
3-3自己的列表
第一种最简单的
bike=['a','b','c','d']
print('i would like to own a '+bike[0])
print('i would like to own a '+bike[1])
第二种用for语句
bike=['a','b','c','d']
for i in bike:
print("i would like to own a",i)
3-4嘉宾名单
names=['mao','zhou','zhu','ren']
print(names)
3-5修改嘉宾名单
还是给出两种方法,都是在本节学的
names=['mao','zhou','zhu','ren']
print(names[0]+" can't come this party")
names[0]='liu'
print(names)
names=['mao','zhou','zhu','ren']
names1=names.pop(0)
print(names1+" can't come this party.")
names.insert(0,'liu')
print(names)
print(names1+" can't come this party.")
注意这一句哦,因为我写的can’t come this party.有个’(单引号) 所以外面必须用双引号“”,唉 ,在这儿卡了一下,希望大家不要犯这种低级错误啊。
3-6添加嘉宾
print("I found a bigger table!")
names = ["mao", "zhou", "zhu"]
names.insert(0, "liu")
names.insert(2, "ren")
names.append("yv")
print(names)
for i in names:
print("Welcome " ,i)
3-7缩减名单
names = ['mao', 'zhou', 'zhu', 'ren', 'liu', 'yv']
print("Because the table could not be served, only two guests could be invited.")
while len(names) > 2:
print(names[-1]+" Sorry, you can't come to dinner.")
names.pop()
for i in range(len(names)):
print(names[0] + " You're still receiving an invitation.")
del names[0]
print(names)
3-8放眼世界
list = ["c", "d", "a", "e", "b"]
print(list)
print(sorted(list))
print(list)
print(sorted(list, reverse=True))
print(list)
list.reverse()
print(list)
list.reverse()
print(list)
list.sort()
print(list)
list.sort(reverse=True)
print(list)
运行结果
['c', 'd', 'a', 'e', 'b']
['a', 'b', 'c', 'd', 'e']
['c', 'd', 'a', 'e', 'b']
['e', 'd', 'c', 'b', 'a']
['c', 'd', 'a', 'e', 'b']
['b', 'e', 'a', 'd', 'c']
['c', 'd', 'a', 'e', 'b']
['a', 'b', 'c', 'd', 'e']
['e', 'd', 'c', 'b', 'a']
3-9晚宴嘉宾
list = ["a","b","c"]
print(len(list))
结果
3
3-10尝试使用函数
def greet():
print('hello')
greet()
不管题目了,最简单的函数题了
3-11有意引发错误
略
唉这个题目更简单吧(滑稽狗头),一不小心报错止不住啊
学习python深度学习扫下方二维码关注