Strings Practicals
1. Basic String Operations
You have the string "Hello, Python!". Write a Python statement to
find the length of this string.
2. String Methods
Given the string " bict131 python programming", write a Python
statement to convert it to title case (capitalize each word).
3. Basic f-String Usage
You have two variables: name = "Zandile" and age = 30. Use an f-
string to print: "My name is Zandile and I am 30 years old."
4. Expression Evaluation in f-strings
Given a = 5 and b = 3, use an f-string to print: "The sum of 5 and 3
is 8" without manually typing 8.
5. Accessing Individual Characters
Given text = "Python", write a statement to print the first and last
characters using positive and negative indexing.
6. String Mutability
Why does the following code produce an error? text = "hello";
text[0] = "H", Use slicing to create a new string with H.
7. Extracting a Substring
Given word = "programming", write a Python statement to extract
"gram" using slicing.
8. Reversing a String
Using slicing, write a Python statement to reverse the string
"Python".
9. Skipping Characters in a Slice
Given sentence = "abcdefgh", write a Python statement to extract
every second character, resulting in "aceg".
10. Finding the Middle Part of a String
Write a Python statement to extract the middle three characters
from "abcdefghi".