Python: STRING cheatsheet

This article provides a comprehensive Python string manipulation cheatsheet, covering essential functions like substring checks, capitalization, replacing text, splitting strings, and checking character types. It offers clear examples and explanations, making it a valuable resource for anyone working with strings in Python.

Rahul S
3 min readSep 10, 2023
word = 'Rahul'
sentence = 'My name is Rahul Sharma'
if word in sentence:
print("The word is in the sentence.")
else:
print("The word is not in the sentence.")

# Converting into lower and upper
print(f"The uppercase 'word' is {word.upper()}")
print(f"The lowercase 'word' is {word.lower()}")

#output = The word is in the sentence.
# The uppercase 'word' is RAHUL
# The lowercase 'word' is rahul
# .strip()
# Removing leading and trailing whitespaces.

string = " I am Anthony Gondalves. .. "
string.strip()

# output = 'I am Anthony Gondalves. ..'
#' '.join(my_list) - Joining the elements of a list into a single string 
#with a space delimiter.

li = ['happy','no','1','39784830','Okie Dokie']
output = " ".join(li)
print(output)

# output = happy no 1 39784830 Okie Dokie

--

--