Created
March 1, 2024 04:03
-
-
Save wila-diaz/745dd1cb1a5db71884a956d96875ac4b to your computer and use it in GitHub Desktop.
startswith & endswith - String methods combined with Single Condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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