KEMBAR78
String Slicing Assignment CBSE Class12 | PDF
0% found this document useful (0 votes)
132 views2 pages

String Slicing Assignment CBSE Class12

The document provides a Python string slicing assignment for CBSE Class 12 students. It includes a string 'WelcomeToCBSEClass12' and a series of questions requiring various slicing techniques to extract specific parts of the string. Each question is accompanied by the correct slicing answer for reference.

Uploaded by

seemabhatia392
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views2 pages

String Slicing Assignment CBSE Class12

The document provides a Python string slicing assignment for CBSE Class 12 students. It includes a string 'WelcomeToCBSEClass12' and a series of questions requiring various slicing techniques to extract specific parts of the string. Each question is accompanied by the correct slicing answer for reference.

Uploaded by

seemabhatia392
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CBSE Class 12 Python - String Slicing Assignment

Given:

text = "WelcomeToCBSEClass12"

Use the above string `text` for all slicing-related questions below.

Instructions:

- All questions are compulsory.

- Write the output or the correct slice for each.

1. Extract the word 'Welcome' from the string.

Answer: text[0:7]

2. Extract the word 'CBSE' using positive indexing.

Answer: text[9:13]

3. Extract the word 'Class12' using negative indexing.

Answer: text[-8:]

4. Write a slice that returns the string 'ToCBSE'.

Answer: text[7:13]

5. Write the slice that extracts characters from index 7 to 10 (inclusive).

Answer: text[7:11]

6. Write a slice to extract every second character from the full string.

Answer: text[::2]

7. Reverse the entire string using slicing.

Answer: text[::-1]

8. Extract 'WelcomeTo' using slicing.


Answer: text[:9]

9. Write a slice to get all characters from index 11 till the end.

Answer: text[11:]

10. Write a slice to get all characters from the beginning to index 6 (inclusive).

Answer: text[:7]

11. Extract the last 5 characters using negative indexing.

Answer: text[-5:]

12. Write a slice that skips one character each time starting from index 0.

Answer: text[::2]

13. Slice the string to exclude the first 3 and last 3 characters.

Answer: text[3:-3]

14. Extract the word 'ToCBSEClass' using slicing.

Answer: text[7:17]

15. Write a slicing statement that results in an empty string.

Answer: text[5:2]

You might also like