Sitemap
LearnPython

From beginners to experts, find code snippets, practical examples, and step-by-step guides to master Python programming

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!

Press enter or click to view image in full size

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

--

--

Shaloo Mathew
Shaloo Mathew

Written by Shaloo Mathew

I love working with data and finding the stories it tells. Through analytics and technology, I aim to turn data into useful insights.

LearnPython
LearnPython

Published in LearnPython

From beginners to experts, find code snippets, practical examples, and step-by-step guides to master Python programming