This article mainly introduces Python List and Tuple type 1. create a list in Python
L = ['Adam ', 95.5, 'Lisa', 85, 'Bart', 59] print L
2. Python accesses the list by index
L = [95.5,] print L [0] print L [1] print L [2] print L [3]
3. access list in reverse order of Python
L = [95.5, 85, 59] print L [-1] print L [-2] print L [-3] print L [-4]
4. add new elements to Python
L = ['Adam ', 'Lisa', 'Bart'] L. insert (2, 'Paul ') print L
5. Python deletes elements from the list
L = ['Adam ', 'Lisa', 'Paul ', 'Bart'] L. pop (3) L. pop (2) print L
6. replacement element in Python
L = ['Adam ', 'Lisa', 'Bart'] L [0] = 'Bart' L [-1] = 'Adam 'print L
7. create tuple in Python
T = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) print t
8. create a single-element tuple in Python
T = ('Adam ',) print t9. variable tuple in Python
T = ('A', 'B', ('A', 'B') print t
For more articles about Python List and Tuple types, refer to PHP Chinese network!