day4 列表,元祖
day4 1~2列表的增删改查
#对列表增加4个元素,可以随时按q停止增加,否则就会一直增加
li = ["alex","wusir","agon","女神","taibai"]
while 1:
sr =input(">>> ").strip()
if sr.strip().upper() == "Q": #或者写成if sr.strip().lower() == "q":
break
else:
li.append(sr)
print(li)
#正向排序
li = [16,2,6,893,9]
li.sort()
print(li)
#倒序排序
li.sort(reverse=True)
print(li)
#反转排序
li.reverse()
print(li)
#正向排序
li = [16,2,6,893,9]
li.sort()
print(li)
#倒序排序
li.sort(reverse=True)
print(li)
#反转排序
li.reverse()
print(li)
#列表嵌套
li = ['taibai','武藤兰','苑昊',['alex','egon',89],23]
'''print(li[1][1])
li[0] =li[0].capitalize()
print(li)
li[2]="苑日天"
print(li)
li[2]=li[2].replace("昊","日天")
print(li)'''
li[3][0]=li[3][0].upper()
print(li)
元祖
#元祖 只读列表,可循环查询,可切片
#儿子不能改,孙子可能可以改
tu =(1,2,3,"alex",[2,3,4,"taibai"],"egon")
tu[4][3]=tu[4][3].upper()
print(tu)
#join
s = "alex"
s="+".join(s)
print(s)
#列表转换成字符串 .join
#字符串转换成列表 .split
li = ["alex","wusir","agon","女神","taibai"]
s = '+++++'.join(li)
print(s)
range [1,2,3,4,5,6...........100..........]
for i in range(0,100):
print(i)
for i in range(0,10,-1):
print(i)
运行结果不会报错,结果是什么也没有
#循坏打印这个列表,遇到列表中的元素也要打印出来
li = [1,2,3,5,'alex',[2,3,4,5,'taibai'],'afds']
for i in li:
if i ==li[5]:
for j in li[5]:
print(j)
else:
print(i)