- Daily Dose of Data Science
- Posts
- 7 Elegant Usages of Underscore in Python
7 Elegant Usages of Underscore in Python
Must-know for Python programmers.
Underscore offers many functionalities in Python.
The above animation highlights 7 of the must-know usages among Python programmers.
Retrieve the last computed value
Placeholder for loop variable
Digit separator
Additionally, you can also use underscore while naming objects, etc:
Single leading underscore to indicate variables for internal use
Single trailing underscore to avoid conflict with keywords
Double leading underscores to invoke name mangling
Double leading and trailing underscores to write magic methods
π Over to you: What other usages have I missed?
π Tell the world what makes this newsletter special for you by leaving a review here :)
π If you liked this post, donβt forget to leave a like β€οΈ. It helps more people discover this newsletter on Substack and tells me that you appreciate reading these daily insights. The button is located towards the bottom of this email.
π If you love reading this newsletter, feel free to share it with friends!
π Sponsor the Daily Dose of Data Science Newsletter. More info here: Sponsorship details.
Find the code for my tips here: GitHub.
Reply