【python】数组与步长

概念

数组:mumber = [1,3,5,7,9,6,7,8,9,10,11,12,13]

数组截取:number[number.startIndex:number.endIndex:1]

数值截取默认形参:数组首索引:数组尾部索引:默认步长1

步长:(类似1个数组值一个阶梯,从数组0值(1)到数组4值(5)步长为4)

案例

    number= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
    test = number[1:10:3]
    print(test)
    test = number[:10:-3]
    print(test)
    test = number[1::3]
    print(test)
    test = number[:10:3]
    print(test)
    test = number[10:1:-3]
    print(test)
    test = number[1:10:]
    print(test)
    test = number[3]
    print(test)
    test = number[1:-3:]
    print(test)

结果

[2, 5, 8]
[16, 13]
[2, 5, 8, 11, 14]
[1, 4, 7, 10]
[11, 8, 5]
[2, 3, 4, 5, 6, 7, 8, 9, 10]
4
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

你可能感兴趣的:(python,python,开发语言)