Are you taking full advantage of Python 3?
Are you sure?
Here are 10 Python 3 features that will change the way you are writing code today.

Are you sure?
Here are 10 Python 3 features that will change the way you are writing code today.



Instead of cluttering your code with constants, you can create an enumeration using the Enum class.
An enumeration is a set of symbolic names bound to unique, constant values.

More information about enumerations:
https://docs.python.org/3.4/library/enum.html
https://pythonspot.com/python-enum/




Using data classes, Python will automatically generate special methods like "_init__" and "__repr__", reducing a lot of the clutter from your code.
This considerably reduces the amount of repetitive code that you had to write before.

More information about data classes:
https://realpython.com/python-data-classes/
https://docs.python.org/3/library/dataclasses.html




The pathlib module provides a way to interact with the file system in a much more convenient way than dealing with os.path or the glob module.
The pathlib module makes everything simpler. When I discovered it, I've never looked back.

More information about the pathlib module:
https://realpython.com/python-pathlib/
https://docs.python.org/3/library/pathlib.html




You can use type hints to indicate the type of a value in your code. For example, you can use it to annotate the arguments of a function and its return type.
These hints make your code more readable, and help tools understand it better.

More information about type hints:
http://veekaybee.github.io/2019/07/08/python-type-hints/
https://docs.python.org/3/library/typing.html




Instead of having to use the .format() method to print your strings, you can use f-strings for a much more convenient way to replace values in your strings.
f-strings are much more readable, concise, and easier to maintain.

More information about f-strings:
https://realpython.com/python-f-strings/
https://www.python.org/dev/peps/pep-0498/




Using this trick, while unpacking an iterable, you can specify a "catch-all" variable that will be assigned a list of the items not assigned to a regular variable.
Simple, but very convenient to keep the code concise.

More information about Extended Iterable Unpacking:
https://www.python.org/dev/peps/pep-3132/
https://www.rfk.id.au/blog/entry/extended-iterable-unpacking/




Using assignment expressions (through the walrus operator :=) you can assign and return a value in the same expression.
This operator makes certain constructs more convenient and helps communicate the intent of your code more clearly.

More information about the Walrus operator:
https://deepsource.io/blog/python-walrus-operator/
https://www.python.org/dev/peps/pep-0572/




The asyncio module is the new way to write concurrent code using the async and await syntax.
This approach allows for much more readable code and abstracts away many of the complexity inherent with concurrent programming.

More information about the asyncio module:
https://realpython.com/async-io-python/
https://docs.python.org/3/library/asyncio.html




This one is a small, nice addition: you can use underscores in numeric literals for improved readability.
This will shave off a few seconds every time you had to count how many digits a number had.


Using the functools.lru_cache decorator, you can wrap any function with a memoizing callable that implements a Least Recently Used (LRU) algorithm to evict the least recently used entries.
Do you want fast code? Look into this.

More information about the lru_cache decorator:
https://docs.python.org/3/library/functools.html#functools.lru_cache
https://www.cameronmacleod.com/blog/python-lru-cache



Are there any specific Python 3 features that you'd like to discuss?