A. Index
1. The index value to the starting value 0, -1 from the end of the start position.
Value Format var [index]
String index
name="hello_shenzhen"
print(name[0])
print(name[1])
print(name[-1])
print(name[-2])
List index
phone=['huawei','sanxing','apple','xiaomi','zhongxin']
print(phone[0])
print(phone[1])
print(phone[-1])
print(phone[-2])
3. multidimensional array index value
"" "Multi-dimensional array, the index value." ""
name=("zhangsan","lisi",("liudehua","telangpu","tainmao"),"wangwu","zhaoliu","wangba")
print(name[2][-1])
Phone = [ 'HUAWEI', 'Sanxing', 'Apple', 'Xiaomi', 'Zhongxin', [ 'huojiya', 'xiaolingtong']]
Print (Phone [0])
Print (Phone [. 1])
Print (Phone [-1])
Print (Phone [-2])
Print (Phone [. 5] [-. 1])
Second slice var [start_index: end_index]
Note: The cut of value does not contain a value end_index
1. tangent
= name "shenzhenwuya"
Print (name [2:. 6]) # value from 3-6
The results: enzh
print(name[3:7])
The results: nzhe
print(name[0:11])
The results: shenzhenwuy
print(name[0:])
The results: shenzhenwuya
print(name[:])
The results: shenzhenwuya
2. fanqie
name="shenzhenwuya"
print(name[:-1])
The results: shenzhenwuy
print(name[:-2])
The results: shenzhenwu
print(name[4:-4])
The results: zhen
- Skip cut
name="shenzhenwuya"
print(name[1:8:])
Results: henzhen
Print (name [. 1:. 8:. 1])
Results: henzhen
Print (name [. 1:. 8: 2])
Results: hnhn
Print (name [. 1:. 8:. 3])
Results: HZN
Print (name [:: 2])
The results: sezewy
4. Anti-skip-cut
name="shenzhenwuya"
print(name[-12:-4:])
Results: Shenzhen
Print (name [-12: -4:. 1])
Results: Shenzhen
Print (name [-12: -4: 2])
Results: SEZE
Print (name [-12: -4:. 3])
Results: SNE
Print (name [::. 3])
The results: sneu
Note : Integer and int dict dictionaries and collections set does not support the index value