Member-only story
Python String Operations- Part 2
In this guide, we’ll explore string operations in Python and cover important string functions. This is a continuation of Part 1, where we introduced the basics of working with strings. Let’s dive in!
We know that we can simply create a string by adding single or double quotes around characters.
Sometimes, the user might need to put quotation marks in between the strings. For example, consider the sentence: He said, “I want to eat an apple”.
How will you print this statement in Python?
print('He said, "I want to eat an apple".')
#OR
print("He said, \\"I want to eat an apple\\".")Output:
He said, "I want to eat an apple".
He said, "I want to eat an apple".String Methods
Python provides a set of built-in methods that we can use to alter and modify the strings. Methods are functions that are specifically tied to string objects. They are called using the dot notation (string.method()).
🔸upper()
The upper() method converts a string to upper case.
Example:
str1 = "AbcDEfghIJ"
print(str1.upper())Output:
ABCDEFGHIJ







