list 学习第一课

list_one = ["","","","","","",""]

#  append()
list_one .append("")
print(list_one )
#['你', '是', '我', '未', '来', '的', '人', '啊']

#   insert()
list_one .insert(1,"")
print(list_one )
#['你', '不', '是', '我', '未', '来', '的', '人', '啊']

#   extend()
a = [1,2,3]
b = [4,5,6]
a.extend(b)
print(a)
#[1, 2, 3, 4, 5, 6]
增加元素 1,append() 2,insert() 3,extend()
list_one = ["","","","","","","",""]

#  remove()   根据元素的值进行删除
list_one .remove("")
print(list_one )
#['你', '是', '我', '未', '来', '的', '人']

#  pop()  根据索引进行删除
list_one = ["","","","","","","",""]
list_one .pop(1)
print(list_one )
#['你', '是', '我', '未', '来', '的', '人']

#del 暴力删除
list_one = ["","","","","","","",""]
del list_one [1]
print(list_one )
#['你', '是', '我', '未', '来', '的', '人']

del list_one [0:3]
print(list_one )
#['未', '来', '的', '人']

#del list_one   #删除整个列表
#print(list_one )
# NameError: name 'list_one' is not defined
删除元素 1,remove() 2,pop() 3,del
list_two = ["","","","","","","Python"]

list_two [6] = "C语言"
print(list_two )
#['人', '生', '苦', '短', '我', '用', 'C语言']

list_two = ["","","","","","","Python"]

list_two [2:4] = ["",""]
print(list_two )
#['人', '生', '很', '甜', '我', '用', 'Python']
修改元素
list_three = [1,2,3,4,5,6,1,1,2,3,1,1,3,4,5]
a = list_three .count(1)
print(a)
#  5
count() 用于计算元素出现的次数
list_four = ["","","",""]
b = list_four  .index("")
print(b)
#   2
index() 用于查找已知元素名称的索引
list_five = [1,2,3,4]
c = sum(list_five )
print(c)
#  10
sum() 用于计算元素的和
# list_name.sort(key=None,reverse=False)

list_six = [1,3,5,2,4,7,8]
list_six .sort()
print(list_six )
#[1, 2, 3, 4, 5, 7, 8]

list_seven= [1,3,5,2,4,7,8]
list_seven .sort(reverse= True)
print(list_seven )
# [8, 7, 5, 4, 3, 2, 1]

list_eight = ["Zhangsan","lisi","wangwu"]
list_eight .sort()
print(list_eight )
#  ['Zhangsan', 'lisi', 'wangwu']   区分大小写  大写在前

list_eight = ["Zhangsan","lisi","wangwu"]
list_eight .sort(key=str.lower)
print(list_eight )
#  ['lisi', 'wangwu', 'Zhangsan']   不区分大小写



#  sortde()     sortde(list_name,key=None,reverse=False)
list_nine = ["xiaoli","xiaohong","daming","Zhangzheng"]
list_ten = sorted(list_nine )
print(list_ten )
#['Zhangzheng', 'daming', 'xiaohong', 'xiaoli']
对列表进行排序 1,sort() 2,sorted()
e = ["小明","小红"]
f = ["小张","小强"]
print(e+f)
#['小明', '小红', '小张', '小强']
序列相加
H = ["乔布斯"]
print(H*5)
#['乔布斯', '乔布斯', '乔布斯', '乔布斯', '乔布斯']
乘法
num = [11,66,33,87,26,97,13,23,6,3,9]
print("最大值为:",max(num))
# 最大值为:97
print("最小值为:",min(num))
# 最小值为:3
print("长度为:",len(num))
#  11
计算序列的最大值,最小值,长度

 

posted @ 2018-07-23 23:21  Springtime  阅读(193)  评论(0)    收藏  举报