1. Tuples
(1, 2, ' A ', ' abc ')
Tuples are read-only data types that, once created, cannot be modified and can only be queried
Query by index, slice query, slice + step query and string query are similar
1 ' a ' ' ABC ' )2print(t[0]) 3print(t[0:2])4 Print(T[0::2])
Note: 3, 4 Prints the tuple data type, the result of the slice query or the tuple
2.list List
L1 = [1, 2, 3, 4, ' A ', ' B ', ' C ']
A list can store different types of data, the elements of a list can be a tuple, or it can be another list, which is called a nested list
Inquire:
The way that list queries and tuple queries are similar to string queries can be analogous to memory.
The index value, from left to right, is zero, and the last index value is the maximum length-1
From right to left, from 1 onwards
Index query, gets the elements of the list,
v = l1[0], result is shaping data 1
Slice Query
SUB2 = L1[0:2] The result is [+]
Slice + Step
SUB3 = L1[::2] The result is [1,3, ' a ', ' C ']
Note: Starting with 0, 0 can be omitted, and the end is the maximum length, or it can be ignored.
Increase:
Append method, append after list
Insert inserts, specifying the index location to add
L1.append ((1, 211)
Extend, methods, which can be followed by strings, tuples, lists such as types of data that can be traversed
L1.extend (' abc ') result is
[1, 2, 3, 4, ' A ', ' B ', ' C ', ' A ', ' B ', ' C ']
Delete:
The Pop method removes the specified element, which can be indexed by the Pop method that returns the element value to be deleted
L1.pop (0)
Remove method, delete the first matching value from left to right, if not, the error
L1.remove (' a ')
Clear method, empty list, list becomes an empty list
L1.clear ()
Del method
Delete Element del l1[0]
See the use of brackets and values, is it possible to expand, delete slices, delete slices + step
Del L1[0:3]
Del L1[::2]
Python fourth day