lst列表索引

# sooele
#
# lst  = ['hello','worol',98,'hello']
#
# print(lst.index('hello'))
# # print(lst.index('Python'))
#
# # print(lst.index('hello',1,3))
# ##从索引1-3查找hello
# print(lst.index('hello',1,4))
# ##从索引1-3查找hello


# lst  = ['hello','worol',98,'hello',234]
# print(lst[2])
# ####获取索引为2的元素
#
# print(lst[10])
# ###########超出范围


lst = [10,20,30,40,50,60,70,80]
#start=1,stop=6,step1
# print(lst[1:6:1])

print(id(lst))
print(lst[1:6])
print(lst[1:6:2])
print(lst[:6:2])
##stop=6 step=2 start默认。
print(lst[1::2])
##stop=默认 step=2 star=1。


print('--------------------------step为负数情况------------')
print(lst[::-1])
print(lst[7::-1])
#start=7 stop省略 step=-1
print(lst[6:0:-2])
#start=6 stop=0 step=-2


 

发表评论