0% found this document useful (0 votes)
2 views

Python String Handling Worksheet

The document outlines a series of exercises focused on Python string handling techniques, including basic operations, string methods, string formatting, and additional tasks. Each exercise requires writing a function to perform specific string manipulations, such as concatenation, length calculation, and palindrome checking. The document emphasizes testing the code and providing screenshots of both the code and its output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python String Handling Worksheet

The document outlines a series of exercises focused on Python string handling techniques, including basic operations, string methods, string formatting, and additional tasks. Each exercise requires writing a function to perform specific string manipulations, such as concatenation, length calculation, and palindrome checking. The document emphasizes testing the code and providing screenshots of both the code and its output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python String Handling Techniques

For each of these exercises identify the string handling method


required, design the Python code, test it and attach a screenshot of
both the code and the output.

Basic Operations:
Exercise 1: Write a function that takes two strings as input and returns their
concatenation.

Exercise 2: Write a function that takes a string as input and returns the length
of the string.

Exercise 3: Write a function that takes a string as input and returns the first
and last characters of the string.
String Methods:
Exercise 1: Write a function that takes a string as input and returns the string
in all uppercase.

def uppercase_string(input_string):
return input_string.upper()

Exercise 2: Write a function that takes a string as input and returns the string
without leading and trailing whitespace.

Exercise 3: Write a function that takes a string as input and returns a list of
words in the string.

Exercise 4: Write a function that takes a list of strings as input and returns a
single string with all the elements concatenated with a space between them.
String Formatting:
Exercise 1: Write a function that takes a name and an age as input and
returns a formatted string like "My name is [name] and I am [age] years old."

Exercise 2: Write a function that takes a list of names as input and returns a
formatted string listing the names with commas and "and" appropriately
placed.
Additional Tasks:
Exercise 1: Write a function that takes a string as input and returns the
reverse of the string.

Exercise 2: Write a function that takes a string as input and returns True if it's
a palindrome, False otherwise.

Exercise 3: Write a function that takes two strings as input and returns True if
they are anagrams of each other, False otherwise.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy