0% found this document useful (0 votes)
2 views1 page

Basic String Operations Practicals

The document provides a series of practical exercises focused on string manipulation in Python. It covers basic string operations, string methods, f-string usage, character access, string mutability, substring extraction, string reversal, character skipping in slices, and finding the middle part of a string. Each exercise includes a specific task to be accomplished using Python code.

Uploaded by

aloziekelechi16
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 views1 page

Basic String Operations Practicals

The document provides a series of practical exercises focused on string manipulation in Python. It covers basic string operations, string methods, f-string usage, character access, string mutability, substring extraction, string reversal, character skipping in slices, and finding the middle part of a string. Each exercise includes a specific task to be accomplished using Python code.

Uploaded by

aloziekelechi16
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

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".

You might also like