10 Coolest Python Features — Part II

Hidden Python features that you may not know

Photo by Chris Ried on Unsplash

This is the continuation of the previous article where we saw 5 coolest features of Python. Please do read it here if you haven’t read it. In this article, we will be seeing another 5 coolest features of Python

6. Dictionary Comprehension

Dictionary Comprehension is similar to List Comprehension. Here we use dictionaries instead of lists.

Consider we want to generate the squares of N numbers in the form of a dictionary, where the key is the number and the value is its square.

Dictionary comprehension

7. F-string


8. Decorators

Consider we want to print the execution time of all the functions that are called in a program. We can easily achieve the above functionality using decorators.

Python Decorator

9. Zfill

Consider we need to print the current date in the format dd-mm-yyyy. We can use Python’s datetime module to get the current date, month, and year.

But if the month or date has a single digit, there won’t be a leading zero. zfill can be used to add a leading zero if the date or month is a single digit.


10. Any and All

any and all

Thank you 🤘