Here are some useful python string methods examples:
- transform a sentece to title:
print("My python text".title())
# output
# My Python Text
- check the ending of a phrase, with endsWith():
# returns a boolean in case that the sentence ends with the
# provided parameter
print("My python text".endswith("."))
# False
print("My python text.".endswith("."))
# True
- remove any tabs, whitespaces from a given string (from the beginning and the end)
# returns a boolean in case that the sentence ends with the
# provided parameter
print(" My python text. ".strip())
# My python text.
- find and replace words or string sequences:
print("I bake good cakes.".replace("good", "amazing"))
# I bake amazing cakes.
Top comments (0)