© 2004-19

Python Strings

Python has many functions and methods that can be used to find information about a string and to change it from say lower case to upper case.
Also, strings in python are treated in a similar way to lists in that individual characters can be interrogated or changed by using their index number.
The table below shows lists some of the most useful of string methods available in Python.

Use this presentation for a more detailed description of how to use strings.
There are a number of exercises to complete on the last 4 slides

Method Description
Splicing strings Quick reference to splice various parts of a string
Wrapt Text Wrap a long line of text by setting the number of columns (characters) to be displayed
find character(s) Find a character or string within another string

Notes: You can optionally specify the start and end position of the search

Change the case of a string Change the case of a string
Check string for numbers and/or letters Check string contents for only letters, only numbers or number and letters

Notes: when testing for letters the string cannot contain spaces

Clean a string Remove whitespace (space and tabs) from the beginning and end of a string
Split a string Split a string into parts based on a character in the string