22nd August 2021
Computer Science⚑
Programming⚑
(../python_basics.md)⚑
-
New: String remove prefix suffix methods.
str.removeprefix(prefix)
: If the string starts with the prefix string, returnstr
. Otherwise, return a copy of the original string.str.removesuffix(suffix)
: If the string ends with the suffix string and that suffix is not empty, returnstr
. Otherwise, return a copy of the original string.
-
New: Current local date and time.
-
New: TypedDict.
Special construct to add type hints to a dictionary. At runtime it is a plain
dict
.Example:
class Point2D(TypedDict): x: int y: int label: str a: Point2D = {'x': 1, 'y': 2, 'label': 'good'} # OK b: Point2D = {'z': 3, 'label': 'bad'} # Fails type check
(../computer_science/programming/python/mypy.md)⚑
-
New: Ignore line for type checking.
To ignore type checking in one particular line of the code, add the comment
# type: ignore
at the end of that line
(../computer_science/programming/python/pydantic.md)⚑
-
New: Root_validator.
Validation can also be performed on the entire model's data.
(../computer_science/programming/python/snippets.md)⚑
-
New: Find in dictionary.
Find first element in dictionary that satisfies a condition:
next(item for item in {dict} if {{ condition }})
Other⚑
-
New: Order of abstractmethod classmethod.
Use
@abstractmethod
beforeclassmethod
. See (https://bugs.python.org/issue16267).