Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

More on strings in Python

Learn programming basics! Understand algorithms, propositional logic, and Python syntax. Create programs and grasp the basics of computer science.

Optional exercise: What other strings methods are there?

In the video you saw some useful string methods including lower, upper, title and replace.

We said that this method is a term used for object-oriented programming, a programming paradigm that we will not have the time to look into. However, knowing the methods that operate on strings can be useful regardless.

Previously, we also explored f-strings.

Optional task: Looking up other strings

In this task, you are asked to research and find out more useful strings methods.

As you do this, note that a good programmer is one that can read documentation. We therefore point you to the String Methods section of the Python documentation.

Read through the methods and see if you can find something useful or interesting.

For example, I find the endswith method really useful. I may want to write a program that checks if a string ends with a specific sub-string. The documentation says: ‘Return True if the string ends with the specified suffix, otherwise return False. suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position.’

Therefore, I could use it like so:

my_string = "Hello, world"
print(my_string.endswith('rld'))

It should print True!

What other methods can you find? Have a look at the documentation and note down anything you find interesting/useful.

This article is from the free online

An Introduction to Programming Using Python

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now