:. For example, first_name: str.intfloatboolbytesThere are some data structures that can contain other values like dict, list, set and tuple. And the internal values can have their own type too → these types that have internal types are called generic types.
You should use the typing standard Python module for these generic types.
typing.Example: Python 3.8+
from typing import List
def process_items(items: List[str]):
for item in items:
print(item)
from typing import Set, Tuple
def process_items(items_t: Tuple[int, int, str], items_s: Set[bytes]):
return items_t, items_s
from typing import Dict
def process_items(prices: Dict[str, float]):
for item_name, item_price in prices.items():
print(item_name)
print(item_price)
Example: Python 3.9+
def process_items(items: list[str]):
for item in items:
print(item)
def process_items(items_t: tuple[int, int, str], items_s: set[bytes]):
return items_t, items_s
def process_items(prices: dict[str, float]):
for item_name, item_price in prices.items():
print(item_name)
print(item_price)
Note → Those internal types in the square brackets are called "type parameters".