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?

πŸ‘‰ Read what others are saying about this post on LinkedIn and Twitter.

πŸ‘‰ 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.

I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn and Twitter.

Reply

or to participate.