name=["张艺兴","吴亦凡","黄景瑜","朴海镇","朴灿烈"]
print(name[4])
print(name[0:2])
print(name[-1])
print(name[-3:-1])
print(name[-3:])
>>>
朴灿烈 ['张艺兴', '吴亦凡'] 朴灿烈 ['黄景瑜', '朴海镇'] ['黄景瑜', '朴海镇', '朴灿烈']
for i in name:
print(i)
print(name[0:-1:2])
>>>
张艺兴 ['李钟硕', '宋钟基'] 111 黄景瑜 朴海镇 朴灿烈 ['张艺兴', '111', '朴海镇']
name.append("张云龙")
print(name)
>>>
['张艺兴', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
name.insert(1,"李易峰")
print(name)
>>>
['张艺兴', '李易峰', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
name[1]="宋钟基"
print(name)
>>>
['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
name.remove("张云龙")
print(name)
>>>
['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈']
del name[4]
print(name)
>>>
['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴灿烈']
name.pop(2)
print(name)
>>>
name=['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
if "朴灿烈" in name:
print('I like he')
>>>
I like he
name=['张艺兴', '宋钟基', '吴亦凡', '黄景瑜', '朴海镇', '朴灿烈', '张云龙']
he="朴灿烈" in name
print(he)
>>>
True
列表的复制
import copy
name=["张艺兴",["李钟硕","宋钟基"],"吴亦凡","黄景瑜","朴海镇","朴灿烈"]
name1=name
name2=copy.copy(name)
name3=name[:]
name4=list(name)
names=name.copy()
name[1][1]="宋钟基好帅啊"
name[0]="张艺兴努力努力"
print(name)
print(name1)
print(name2)
print(name3)
print(name4)
print(names)
>>>