
These features will allow you to create code that flows when writing and reads effortlessly

These features will allow you to create code that flows when writing and reads effortlessly
I am including the full text of the post
Despite not being a pure functional language, a lot of praise that python receives are for features that stem from functional paradigms. Many are second nature to python programmers, but over the years I have seen people miss out on some important features. I gathered a few, along with examples, to give a brief demonstration of the convenience they can bring.
if/else
with or
With values that might be None
, you can use or
instead of if/else
to provide a default. I had used this for years with Javascript, without knowing it was also possible in Python.
python
def get_greeting_prefix(user_title: str | None): if user_title: return user_title return ""
Above snippet can shortened to this:
python
def get_greeting_prefix(user_title: str | None): return user_title or ""
The overdue arrival of match
to python means that so many switch
style statements are expresse