Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 576 Bytes

20240130100737.md

File metadata and controls

22 lines (15 loc) · 576 Bytes

startswith can receive a tuple

Simplify your code using a tuple in str.startswith() 🚀

Did you know that you can use a tuple of strings as an argument in the startswith() method?

See a quick refactoring below. With just one line, you can check for multiple prefixes. 🌟

This makes your code cleaner 😍 📈

def is_url(path):
    return path.startswith('http://') \
            or path.startswith('https://') \
            or path.startswith('ftp://')

# refactored
def is_url(path):
    return path.startswith(('http://', 'https://', 'ftp://'))

#strings