Skip to content
techsnow

Python Basics

String Methods

text = "  Learn Python Today  "

text.strip()           # "Learn Python Today"
text.lower()           # "  learn python today  "
text.upper()           # "  LEARN PYTHON TODAY  "
text.replace("Today", "Now")
text.strip().split(" ")  # ['Learn', 'Python', 'Today']
" - ".join(["a", "b"])   # "a - b"
"python".capitalize()    # "Python"
"hello".startswith("he") # True
"banana".count("a")      # 3
"Python" in text         # True