Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wila-diaz/745dd1cb1a5db71884a956d96875ac4b to your computer and use it in GitHub Desktop.
Save wila-diaz/745dd1cb1a5db71884a956d96875ac4b to your computer and use it in GitHub Desktop.
startswith & endswith - String methods combined with Single Condition
# In this gist, I want to share 2 concepts:
# 1. Use startswith (similar with endswith) method.
# 2. Use single conditions instead of multiple conditions.
names = ["Wilmer", "Elong", "Linus", "Cristiano" ]
# classic use with or condition
for name in names:
if name.startswith("W") or name.startswith("Cr"):
print(name)
#modern use
for name in names:
if name.startswith(("W", "Cr")):
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment