Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Python contains a lot of string manipulation “methods”.

A string is actually an object and the


method is separated by the string name by a dot, for example:

Computer Experiment 1
Change the names defined in fn and sn to other lower case names and then run the
program, to understand what capitalise does.

You can access a part of a string and create another string, look at the following program

Run this program and note the output. Change the numerical values of start and finish, and
run again; do this a few times to understand how this works.

Exercise 1
You are in charge of new email accounts. The email of a person consists of the first three
letters of their first name and first three letters of their last name, joined together. Write a
program where the user inputs their first name and last name. The output is their email
address’s first six letters.

You can search for a string inside a string using the find method:
Computer Experiment 2
In the above program change the cities that define b, but keep it to within the list of cities
shown. Is the program case sensitive i.e. do you get the same value for Goteborg and
goteborg?

Exercise 2
Write a program where the user enters their first name and second name. The program
capitalised their first can second name and prints to screen. You will need to use the
str.capitalize() method. Read this link:
https://www.tutorialspoint.com/python/string_capitalize.htm

More string methods can be found here:


https://www.tutorialspoint.com/python/python_strings.htm

You might also like