Worksheet: Strings in Python
Section A: MCQs (1 Mark Each)
1. What is the output of the following code? s = "Python" print(s[1:4])
a) Pyt b) yth c) tho d) ytho
2. Which of the following methods is used to remove any whitespace from the beginning or
the end of a string?
a) strip() b) split() c) replace() d) find()
3. What will be the output of the following code?
s = "hello"
print(s.upper())
a) HELLO b) hello c) error d) hELLO
4. Which of the following is not a valid string method in Python?
a) upper() b) reverse() c) split() d) join()
5. What is the result of the following expression?
"Python" * 2
a) Python2 b) Python Python c) PythonPython d) Error
Section B: Very Short Questions (2 Marks Each)
1. What is a string in Python?
2. How can you access the last character of a string?
3. Explain the use of the find() method.
4. What does the split() method do in a string?
5. What is string slicing in Python? Give an example.
Section C: Programming Questions (3 Marks Each)
1. Write a Python program to check if a string is a palindrome.
2. Write a Python program to count the number of vowels in a given string.
3. Write a Python program to reverse a given string.
4. Write a Python program to replace all spaces in a string with an underscore (_).
5. Write a Python program to find the length of a string without using the len() function.