You can now print out a variable even easier!
# Before
my_var = "hi"
print(f"my_var={my_var}")
# After
my_var = "hi"
print(f"{my_var=}")
You can now combine two dictionaries with the |
operator
# Before
dct = dict(a=1)
dct = {**dct, {"b": 2}}
# After
dct = dict(a=1)
dct = dct | {"b": 2}
# After, even better
dct = dict(a=1)
dct |= {"b": 2}
- In python 3.6, dictionaries were ordered by accident.
- From python 3.7 onwards, dictionaries are ordered by design and will stay that way.
- In python 3.8, the
csv.DictReader
now returns adict
type and not anOrderedDict
type
Before python 3.9, to type many builtin objects you had to import those classes from the typing
module.
Now, you can type the generic data type.
# Before
from typing import List, Dict
def my_func(*, a: List, b: Dict) -> bool:
return True
my_func(a=[], b={})
# After
def my_func(*, a: list, b: dict) -> bool:
return True
my_func(a=[], b={})
When doing type annotations, there is a new union operator.
# Before
from typing import Union, Optional
def a() -> Union[str, int]:
return 'abc' if True else 1
def b() -> Optional[str]:
return 'abc' if True else None
# After
def a() -> str | int:
return 'abc' if True else 1
def b() -> str | None:
return 'abc' if True else None