Python: Sequence Types
In Python, String, List, Tuple, are called “sequence types”. They all have the same methods. Here's example of operations that can be used on sequence type.
# operations on sequence types # a list ss = [0, 1, 2, 3] # length print(len(ss)) # 4 # ith item print(ss[0]) # 0 # slice of items print(ss[0:3]) # [0, 1, 2] # slice of items with jump step print(ss[0:10:2]) # [0, 2] # check if a element exist print(3 in ss) # True. (or False) # check if a element does NOT exist print(3 not in ss) # False # concatenation print(ss + ss) # [0, 1, 2, 3, 0, 1, 2, 3] # repeat print(ss * 2) # [0, 1, 2, 3, 0, 1, 2, 3] # smallest item print(min(ss)) # 0 # largest item print(max(ss)) # 3 # index of the first occurrence print(ss.index(3)) # 3 # total number of occurrences print(ss.count(3)) # 1
Python, Data Structure
- Python: List
- Python: Generate List: range
- Python: List Comprehension
- Python: List Methods
- Python: Iterate List
- Python: Map f to List
- Python: Filter List
- Python: Iterator to List
- Python: Copy Nested List, Shallow/Deep Copy
- Python: Interweave Lists to Tuples, Transpose
- Python: Sort
- Python: Convert List to Dictionary
- Python: Dictionary
- Python: Iterate Dictionary
- Python: Dictionary Methods
- Python: Tuple
- Python: Sets, Union, Intersection
- Python: Sequence Types
- Python: Read Write JSON