Python String Handling Worksheet
Python String Handling Worksheet
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.