A Hidden Feature of a Popular String Method in Python

Reducing the number of conditions.

Here's something new and cool I recently learned about a string method in Python.

In Python, the startswith and endswith string methods are commonly used to match a substring at the start and end of the string.

However, did you know you can also pass multiple substrings as a tuple to these methods?

This prevents you from writing multiple conditions while preserving the same functionality.

πŸ‘‰ Over to you: What are some other hidden features of some common methods in Python that you are aware of? Let me know :)

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