Python typ hint - ghdrako/doc_snipets GitHub Wiki
tags:
- programming
- python
Python typ hint
def generate_stats(measures: list) -> tuple:
def calculate_product(a: int, b: int, multiplier: int = 1) -> int:
def assign_task(pending_task: Task, user: User):
pass
def complete_tasks_hinted(tasks: list[Task]):
def generate_stats(measures: list[float] | tuple[float, ...]) ➥ -> tuple[float, float]:
# Sequence can capture any sequence data types
from typing import Sequence
def generate_stats(measures: Sequence[float]) -> tuple[float, float]:
set[int | str]
para0: int | float | str | list
| Container type | Code examples | Explanation |
|---|---|---|
| list | list[str] | A list of str objects |
| list | list[int] | A list of int objects |
| tuple | tuple[float, int] | A tuple of a float object and an int object |
| Tuple | tuple[float, ...] | A tuple of multiple float objects |
| dict | dict[int, str] | A dict of keys using int objects and values using str objects |
| dicta | dict[int, list[int]] | A dict of keys using int objects and values using list objects of int objects |
| set | set[int] | A set of int objects |
| set | set[str] | A set of str objects Listing |