python基础(九)--列表
作者:互联网
# li = ['alex',[1,2,3],'wusir','egon','女神','taibai']
# l1 = li[0]
# print(l1)
# l2 = li[1]
# print(l2)
# l3 = li[0:3]
# print(l3)
li = ['alex','wusir','egon','女神','taibai']
#增加 append insert
# li.append('日天')
# li.append(1)
# print(li)
# while 1:
# username = input('>>>')
# if username.strip().upper() == 'Q':
# break
# else:
# li.append(username)
# print(li)
# li.insert(4,'春哥')
# print(li)
# li.extend('二哥') 可迭代,添加单个元素,添加到最后
# li.extend([1,2,3])
# print(li)
#删
li = ['taibai','alex','wusir','egon','女神',]
# name = li.pop(1) # 返回值
# name = li.pop() # 默认删除最后一个
# print(name,li)
# li.remove('taibai') # 按元素去删除
# print(li)
# li.clear() # 清空
# print(li)
# del li
# del li[0:2] # 切片去删除
# print(li)
#改
# li[0] = '男兽'
# li[0] = [1,2,3]
#切片 把最小元素逐个添加到列表中,
# li[0:3] = '云姐plfdslkmgdfjglk'
# li[0:3] = [1,2,3,'春哥','咸鱼哥']
# print(li)
#查
# for i in li:
# print(i)
# print(li[0:2])
#公共方法:
# l = len(li)
# print(l)
# num = li.count('taibai')
# print(num)
# print(li.index('wusir'))
# li = [1,5,4,7,6,2,3]
# #正向排序
# # li.sort()
# # print(li)
# #反向排序
# # li.sort(reverse=True)
# # print(li)
# #反转
# li.reverse()
# print(li)
#列表的嵌套
li = ['taibai','武藤兰','苑昊',['alex','egon',89],23]
# print(li[1][1])
# name = li[0].capitalize()
# # print(name)
# li[0] = name
# li[0] = li[0].capitalize()
# li[2] = '苑日天'
# print(li[2].replace('昊','ritian'))
# li[2] = li[2].replace('昊','ritian')
# li[3][0] = li[3][0].upper()
# print(li)
标签:name,python,基础,li,taibai,wusir,print,列表,append 来源: https://www.cnblogs.com/qingmuzi/p/12614271.html