#-------------------------------------------------------------------------------
# 测试列表冒号用法
#-------------------------------------------------------------------------------
def main():
ls = [0,1,2,3,4,5,6,7,8,9]
print('ls is:',ls)
print('ls[2::] is:',ls[2::])
print('ls[2:-1]is:',ls[2:-1])
print('ls[2:9] is:',ls[2:9])
print('ls[::3] is:',ls[::3])
print('ls[:] is', ls[:])
if __name__ == '__main__':
main()
测试1:
>>>
ls is: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
ls[2::] is: [2, 3, 4, 5, 6, 7, 8, 9]
ls[2:-1]is: [2, 3, 4, 5, 6, 7, 8]
ls[2:9] is: [2, 3, 4, 5, 6, 7, 8]
ls[::3] is: [0, 3, 6, 9]
ls[:] is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>