今日想学习Python,在此每日打卡
一、2021-5-10
二、使用步骤
1.代码
代码如下:
#2021-5-10练习
#3—1
names=['圆圆','阿莹','欢欢']
print(names[0])
print(names[-1])
#3-2
print("你好,"+ names[1]+ "。")
#3-4
names=['圆圆','阿莹','欢欢']
print("我想邀请"+names[0]+names[1]+names[2]+"共进晚餐")
#3-5
print(names[2]+"无法赴约")
names[2]="方方"
print("我想邀请"+names[0]+names[1]+names[2]+"共进晚餐")
#3-6
print("我找到了更大的餐桌")
names.insert(0,"晴晴")
names.insert(2,"彤彤")
names.append("莹莹")
print("我想邀请"+names[0]+names[1]+names[2]+names[3]+names[4]+names[5]+"共进晚餐")
#3-7
print("我只能邀请两位朋友")
poped1=names.pop(1)
print("非常抱歉,"+poped1+","+"无法邀请你共进晚餐")
poped2=names.pop(0)
print("非常抱歉,"+poped2+","+"无法邀请你共进晚餐")
del names[0]
del names[1]
print("我最后邀请了"+str(len(names))+"个朋友") #注意字符串化
#3-8
places=["landon","new york","beijing","qingdao","yunnan"]
print("This is the origianl list:"+str(places)) #在print中使用列表要将其字符串化
print("This is the sorted list:"+str(sorted(places)))
print("This is the origianl list:"+str(places))
#places.sorted(reverse=True)
print("This is the reverse sorted list:"+str(sorted(places,reverse=True)))
print("This is the origianl list:"+str(places))
places.reverse()
print("This is the reversed list:"+str(places))
places.reverse()
print("This is the origianl list:"+str(places))
places.sort()
print("This is the sort list:"+str(places)) #注意!!!sort是方法,不是函数
places.sort(reverse=True)
print("This is the reverse sort list:"+str(places))
2.运行截图
截图如下: