Member-only story
30 Python Language Tricks That Will Make You a Better Coder
If you think you mastered the language, you’ve got to read this
There are lots of little tricks that can make life easier for a Python coder. Some of these will be known to you, but I’m sure there are at least a couple that you haven’t seen before.
If you’re done reading, also take a look at our latest article on concurrency:
1. The Python Ellipsis
The Python ellipsis is a sequence of three dots. It’s used a lot in conventional (non-programming) languages. But what you might not know, is that it’s a valid object in Python too:
>>> ...
EllipsisIts primary use seems to be in matrix slicing operations in NumPy. However, you can use it as a placeholder in a function that you haven’t implemented yet, instead of using pass, as most people do:
def my_awesome_func():
...This is valid Python code, and it doesn’t look too bad now, does it?
2. Data classes
Since version 3.7, Python offers data classes. There are several advantages over regular classes or other alternatives like returning multiple values or dictionaries:
- a data class requires a minimal amount of code
- you can compare data classes because
__eq__is implemented for you - you can easily print a data class for debugging because
__repr__is implemented as well - data classes require type hints, reduced the chances of bugs
Here’s an example of a data class at work:

