sch = ['schkevin','schdurant','schpaul','schgeorge']
print(sch)
sch +=['schallen','schiversion']
print(sch)
# 循环遍历列表元素
print("$$$$$$$$循环遍历元素$$$$$$$")
for s in sch:
print(s.title(), end=' ')
print()
#列表切片
sch_slice = sch[1:4]
print(sch_slice)
# 可以通过完整切片操作来复制列表
print("$$$$$$$$完整切片复制列表$$$$$$$")
sch_all = sch[:]
print(sch_all)
sch_1 = sch[-3:-1]
print(sch_1)
# 可以通过反向切片操作来获得倒转后的列表的拷贝
print("$$$$$$$$反转后列表$$$$$$$")
sch_2 = sch[::-1]
print(sch_2)
sch_3 = sch[::-2]
print(sch_3)
"D:\Program Files\Python\python.exe" D:/Users/Administrator/PycharmProjects/schPy/schdemo20211126/list_schwinn_2.py
['schkevin', 'schdurant', 'schpaul', 'schgeorge']
['schkevin', 'schdurant', 'schpaul', 'schgeorge', 'schallen', 'schiversion']
$$$$$$$$循环遍历元素$$$$$$$
Schkevin Schdurant Schpaul Schgeorge Schallen Schiversion
['schdurant', 'schpaul', 'schgeorge']
$$$$$$$$完整切片复制列表$$$$$$$
['schkevin', 'schdurant', 'schpaul', 'schgeorge', 'schallen', 'schiversion']
['schgeorge', 'schallen']
$$$$$$$$反转后列表$$$$$$$
['schiversion', 'schallen', 'schgeorge', 'schpaul', 'schdurant', 'schkevin']
['schiversion', 'schgeorge', 'schdurant']
|