Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

30 July Strings in Python

Uploaded by

gauraansh984
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)
4 views2 pages

30 July Strings in Python

Uploaded by

gauraansh984
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
You are on page 1/ 2

THE JAIN INTERNATIONAL SCHOOL, KANPUR

Class:XI Subject:CS Worksheet- Strings in Python Date:30/07/2024


----------------------------------------------------------------------------------------------------------------------------------
Fill in the blanks
1. The data or text enclosed with single quote, double quote or triple quote is known as _____________.
2. The string which is having 0 characters is known as ___________.
3. Each character in a string has a unique position or ID in the text, that is known as ___________.
4. The index of string is start from _______ to ___________ in forward direction.
5. The process of accessing a string character by character is known as __________.
6. The ___________ operator is used to repeat the word or specified text n times.
7. To join more than two words you can use __________ operator.
8. The ______________ operator returns True if a character or specified atring is available in the given string.
9. The _________ and ____________ operators are membership operators.
10. To reverse a string using string slice, __________ is an easy way to do so.

Multiple Choice Questions


1. Which of the following is the correct way of indexes of string, begin from the reverse in backward
direction?
i) 0 to Length – 1 ii) -1 to –length iii) -length to – 1 iv) Length -1 to 0
a) i), ii) and iii) b) ii) and iv) c) Only Option ii) d) ii), iii) and iv)
2. Iterating through the various elements of a string, one character at a time is known as _
a) String Indexing b) String Traversing c) String Replicating d) None
3. When you write S[-5] for a five letter word, python will return
a) S[0] b) S[1] c) S[5] d) S[-5]
4. What will be the result of this code: ‘2’ + 3
a) 5 b) 23 c) Error d) 1
5. What will be the result of this code: ‘*’ * 3
a) Error b) *3 c) *** d) 3*
6. The expression “CSIP” in “TutorialAICSIP” returns
a) Found b) True c) 0 d) 1
7. The expression “Tutor” <=”TutorialAICSIP” returns
a) 1 b) True c) 0 d) False
8. Which of the following function returns the ASCII code for specified character?
a) ASCII() b) asc() c) ord() d) code()
9. Which of the following function returns the character from given integer code?
a) char() b) ord() c) cha() d) chr()
10. What will be the result of s[len(s),-3]
a) Return 3 letters from reverse b) Error
c) First 3 letters of string d) None of these
11. To print first 4 letters from the string, which of the option(s) is/are correct?
i) s[:3] ii) s[0:4] iii) s[:4] iv) s[0:3]
a) Option i) and iv) b) Option ii) and iii) c) Option ii) Only d) Option iii) only
12. Which of the following is not a correct string operation in python?
a) ‘Tut’ + ‘or’ b) ‘Tutor’ * 2 c) ‘Tutor’ + 2 d) 2 * ‘Tutor’
Short answer questions
1. What do you mean by a string? How it differs from other data types?
2. Justify the statement – “Python strings are immutable”.
3. What do you mean by index? What is the key role of indexes in a python string?
4. What do you mean by traversing? Elaborate your answer with an example.
5. Write code to print alternate characters of the given string in the output.
6. What are the differences between + and * operator in the string?
7. How to work with ASCII values in python? Explain all the possible ways or functions deals with ASCII
values in python. Support your answer with at least one example of each.
Output Based Questions
Observe the following code and predict the output:
[1] Code 1:
a = str("786")
b = "Python" * 4
print(a,b)
a=a+b
print(len(a))
[2] Code 2:
s="python string fun"
for i in range(0,len(s)):
if s[i]>='c' and s[i]<='l':
print(s[i].lower(),end="")
else:
print(s[i].upper(),end="")
Answer the following:
1. Write a python program to reverse words in a given String Python
Sample Input : Narain Ji Srivastava
Output : Srivastava Ji Narain
2. Write a Python program input String and remove character from string.
3. Write a Python program to capitalize the first and last character of each word in a string
4. program to read a string and display it in form.
first character last character
second character second last character
5. Program that reads a line and prints its statistics like :
1. Number of uppercase letters :
2. Number of lowercase letters :
3. Number of alphabets :
4. Number of digits :
6. Program that reads a line and a substring. It should then display the number of occurrences of the given
substring in the line.
7. Write a program that takes a string with multiple words and then capitalizes the letter of each word and forms a
new string out of it.
8. Write a program that reads a string and checks whether it is a palindrome string or not.
9. Write a program that reads a string and displays the largest substring of the given string having just the
consonants. ( string manipulation in python)
10. write a program that reads and then prints a string that capitalizes every other letter in the string e.g., passion
becomes pAsSiOn
11. write a program that reads email-id of a person in the form of a string and ensures that it belongs to domain
@edupillar.com. (Assumption : No invalid characters are there in email-id).
12. Python program to print even length words in a string.
13. Remove all duplicates from a given string.
14. Capitalize the first and last character of each word in a string
15. Avoid Spaces in string length.
16. Least Frequent Character in String.
17. Find words which are greater than given length k.
18. what will be the output:
print("a\u00b2") ;print("H\u2082CO\u2083")
19. Remove special characters from String.
20. Swap commas and dots in a String.

You might also like