
Table of Content
- Practice Questions of String in Python – Test 1
- Practice Questions of String in Python – Test 2
- Practice Questions of String in Python – Test 3
- Practice Questions of String in Python – Test 4
- Practice Questions of String in Python – Test 5
- Practice Questions of String in Python – Test 6
- Practice Questions of String in Python – Test 7
- Practice Questions of String in Python – Test 8
- Practice Questions of String in Python – Test 9
- Practice Questions of String in Python – Test 10
Practice Questions of String in Python – Test 1
Q1. What is String in Python?
Q2. Is there any difference in ‘a’ or “a” in python?
Q3. Is there any difference between 1 or ‘1’ in python?
Q4. Python treats single quotes same as double quotes.(T/F)
Q5. A string with zero character is called __________ string.
Q6. Python does not support a character type.(T/F)
Q7. Write a code to store following String in a variable named ‘str’. This is Amit’s Blog
Q8. Write the output of the following code: str1 = "Welcome to my blog" str2 = "Welcome to my \n Blog" print(str1) print(str2)Ans. Welcome to my blog Welcome to my Blog
Q9. Write the output of the following. str1 = "Welcome \tto my Blog" str2 = "Welcome to\n my \tBlog print(str1) print(str2)Ans. Welcome to my Blog Welcome to my Blog
Q10. Write the output of the following.
str1 = “”” Welcome to my
blog.
This is for
Class X”””
print(str1)
Ans. Welcome to my blog. This is for Class X

Practice Questions of String in Python – Test 2
Q1. Write the output of following code-
a) str="hello"
print(str[:3])Ans : hel
b) str=’My Blog’
a=’ ‘
for i in range(len(str)):
a+=str[i]
print(a)
Ans: My Blog
c)Â Â Â Â Â Â Â Â Â Â Â Â Â str='MyBLog'Â Â Â Â Â Â Â Â Â Â Â Â Â Â
a=' '
               for i in range(len(str)):
                 print(i * str[i])Ans: y BB LLL oooo ggggg
d)
s='My'
s1='Blog'
s2=s[:1]+s1[len(s1)-1:]
print(s2)
Ans. Mg
e) print(“My”+’Blog’ * 2)
Ans. MyBlogBlog
f) print(“My” *3 + “Blog” +’7′)
Ans. MyMyMyBlog7
g) for i in range(2,7,2):
print(i * '2')Ans.222222222222
h) for i in range(3,12, 2):
print("a".upper())
Ans.
A
A
A
A
Ai) for i in range(3,12,13):
print("a".upper)
Ans. <built-in method upper of str object at (some memory address)>j) s='Welcome to My Site https://csiplearninghub.com '
print(s.find('come'))
print(s.find('o'))
print(s.find('o', 10, 20))
print(s.find('o', 5, 10))
Ans.
3
4
-1
9Practice Questions of String in Python – Test 3

Q1. Write a code to create empty string 'str1'Ans. str1 = ' 'Q2. What do you mean by traversing a string?Ans. Traversing a string means accessing all the elements of the string one by one by using index value.Q3. What is the index value of first element of a string?Ans. 0Q4. What is the index value of last element of a string?Ans. -1Q5. If the length of the string is 10 then what would be the positive index value of last element?Ans. 9Q6. If the length of string is 9, what would be the index value of middle element?Ans. 4Q7. Index value of a string can be in float. (T/F)Ans. FalseQ8. What type of error is returned by following statement, if the length of string 'str1' is 10. print(str1[13])Ans. Index errorQ9. Write the output of the following: str1 = "Welcome to my Blog" a. print(str1[-1]) b. print(str1[9])Ans g oQ10. Write a code to assign a string "Hello World"' to a string variable named "str1".Ans. str1 = "Hello World"

Practice Questions of String in Python – Test 4
Q1. Write a program to display each character of the following string in separate line using 'for' loop.
str1 = Welcome to My Blog
Ans.
str1 = "Welcome to my Blog"
for i in str1:
print(i)
Q2. Write a program to display each character of the following string in separate line using 'while' loop.
str1 = Welcome to My Blog
Ans.
str1 = "Welcome to my Blog"
c = 0
while c <len(str1):
print(str1[c])
c = c + 1
Q3. Index value of string "str1" varies from 0 to len(str1)-1. (T/F)
Ans. True
Q4. Write the positive and negative index value of 'B' in the following string.
"Welcome to my Blog"
Ans. positive index of B is = 14
negative index of B is = -4
Q5. What do you mean by concatenation of string?
Ans. Joining of two or more string is called concatenation. for example
a = 'Amit'
b = 'Sethi'
c = a + b
Q6. Which of the following is an example of concatenation?
a. 6 + 3
b. '6' + '3'
c. 'a' + 'b' + 'c'
Ans. b and c
Q7. Write a program to count the length of string without using inbuilt function.
Ans.
str1 = "Welcome to my Blog"
c = 0
for i in str1:
c = c + 1
print("length of string is", c)
Q8. Write the output of the following statement.
str1 = "Welcome to my Blog"
for i in str1:
print(i)
print(i, end =' ')
print(i, end = '#')
Ans.
A
A A#m
m m#i
i i#t
t t#
Q9. Write the output of the following statement.
str1 = "Amit"
for i in str1:
print(i)
print(i, end =' ')
Ans.
A
A m
m i
i t
t
Q10. Write the output of the following statement.
str1 = "Welcome to my Blog"
for i in str1:
print(i)
print(i, end =' ')
print(i, end = '#')
Ans.
A
A m
m i
i t
t t #
Practice Questions of String in Python – Test 5
Q1. Match the Following
| Column-1 | Column-2 |
| Slicing | string[range] + ‘x’ |
| Concatenation | string[: – 1] |
| Repetition | string[range] |
| Membership | string1 + string2 |
| Reverse | in, not in |
Solution
| Column-1 | Column-2 |
| Slicing | string[range] |
| Concatenation | string1 + string2 |
| Repetition | string * 7 |
| Membership | in, not in |
| Reverse | string[: – 1] |
Q2. Write the code to join string 'str1' and 'str2' and store the result in variable 'str3'Ans. str3 = str1 + str2Q3. The ___________ operator join the string.Ans. +Q4. What type of error is shown by following code? >>> 2 + '3'Ans. TypeErrorQ5. Which operator is used to replicate string?Ans. *Q6. Write the output of the following. >>> 'A' * 3Ans. AAAQ7. Write the output of the following: for i in range(2,5,2): print(i * '@')Ans. @@ @@@@Q8. 'in' or 'not in' are the _________ operatorAns. MembershipQ9. Write the output of the following >>> 'h' in 'Hindi' >>>'i' in 'Hindi'Ans. False TrueQ10. Write the output of the following for i in "Amit": print(i in "Amit")Ans True True True True

Practice Questions of String in Python – Test 6
Q1. Write the output of the following >>>"string" in "substring" >>>"string" not in "substring"Ans. True FalseQ2. Write the output of the following: >>>'tie' == 'ties' >>>"Amit" != "Amitabh" >>>"amit" > "Amitabh"Ans. False True TrueQ3. Write the full form of ASCIIAns. American Standard Code of Information InterchangeQ4. Write the ASCII value of 'A' and 'a'.Ans. A = 65, a = 97Q5. String Slicing is used to fetch substring from a string. (T/F)Ans. TrueQ6. Write the output of the following. S = "Welcome to my Blog" print(S[2 : 3]) print(S[2 : 10]) print(S[-2 : ]) print(S[-10 : -2 : 2])Ans l lcome to og t yBQ7. Strings are mutable.(T/F)Ans. FalseQ8. Write the output of the following >>>str1 = "Anita" >>>str1[1] = 'm' >>>print(str1)Ans. TypeErrorQ9. Name any two built in function associated with string.Ans. len() and capitalize()Q10. Which function of string return the numerical value?Ans. len()

Practice Questions of String in Python – Test 7
Q1. What is the value returned by find() function for an unsuccessful search?Ans. -1Q2. isalpha() returns True if the string contains only alphabet.(T/F)Ans. TrueQ3. Write the output of the following str1 = "Amit" str2 = "My Blog" str3 = "#blog" str4 = "My 1st Blog" print(str1.isalpha()) print(str2.isalpha()) print(str3.isalpha()) print(str4.isalpha()) Specify the reason if any of the above print statement return False.Ans. True False : Return False as str2 conains spaces False : Returns False as str3 contain special character False : Return False as str4 contain digit and spaces.Q4. Write a program to accept string and display total number of alphabets.Ans. str1 = input("Enter any string") c=0 for i in str1: if i.isalpha()==True: c = c+ 1 print("Total number of alphabets are", c)Q5. Write a program to accept a string and display the sum of the digits, if any present in string. for example: input string : My position is 1st and my friend come on 4th output : 5Ans: str1 = input("Enter any string") n=0 s=0 for i in str1: if i.isdigit() == True: n = int(i) s = s+n print(sum of the diit is ", s)Q6. Write the output of the following: >>>a = 123 >>>b = "123" >>>b.isdigit() >>>a.isdigit()Ans True ErrorQ7. What is the difference between lower() and islower()?Ans. lower() function converts the given string in lowercase while islower() check whether given string is in lowercase r not.Q8. Write a program to accept a string and convert it into lowercase.Ans. str1 = input("Enter any string") print(str1.lower())Q9. Write a program to count the number of lowercase and uppercase character in a string accepted from the user.Ans. str1 = input("Enter any string") for i in str1: if i.islower()==True: l = l+1 if i.isupper() == True: u = u+1 print("Total uppercase characters are--",u) print("Total lowercase characters are--",l)Q10. Write the output of the following: >>>s = "My blog" >>>s.upper() >>>s.lower() >>>s.islower() >>>s.isupper() >>>s.isalpha() >>>s.isdigit()Ans. MY BLOG my blog False False False False

Practice Questions of String in Python – Test 8
Q1. What is lstrip () function in String?Ans. lstrip() function simply remove the spaces or specified characters from the left of the string.Q2. Write the output of the following.(# represents the spaces) >>>str1 = "Welcome to my Blog" >>>print(len(str1)) >>>str2 = "###Welcome to my Blog" >>>print(len(str2)) >>>print(len(str2.lstrip()))Ans. 18 21 18Q3. Write the output of the following.(# represents the spaces) >>>str2 = "###Welcome to my Blog####" >>>print(len(str2)) >>>print(len(str2.strip())) >>>print(len(str2.rstrip()))Ans. 25 18 21Q4. Write the output of the following. >>>str1 = "Welcome to my Blog" >>>print(str1.rstrip('og')) >>>print(str1.lstrip('We')) >>>print(str1.strip('Welog))Ans. Welcome to my Bl lcome to my Blog lcome to my BQ5. Write the output of the following. >>>print(len(str1.rstrip('og'))) >>>print(len(str1.lstrip('We'))) >>>print(len(str1.strip('Welog)))Ans 16 16 13Q6. isspace() returns True if the string contain only spaces (T/F)Ans. TrueQ7. Write the output of the following >>>s1 = " " >>>s2 = " Amit" >>>print(s1.isspace()) >>>print(s2.isspace())Ans. True FalseQ8. Define the following function with example a. istitle() b.swapcase()Ans. istitle() - This function returns True if the string is in titlecase only otherwise returns False. for example s = "Welcome To My Blog" print(s.istitle()) The above code returns True as the string 's' is in Title case. swapcase() - This function converts all the lowercase characters to uppercase and vice versa for example s = "Welcome To My Blog" print(s.swapcase()) Output: wELCOME tO mY bLOG

Practice Questions of String in Python – Test 9
Practice Questions of String in Python - Test 9 Q1. Write the output of the following: str1 = "Welcome to my Blog" a. print(len(str1)) b. print(capitalize(str1))Ans. a. 18 b. Welcome to my blogQ2. Write the output of the following. >>>str1 = "Welcome to my Blog" >>>x = str1.split() >>>print(x)Ans. ['welcome', 'to', 'my', 'blog']Q3. Write a program to accept a string and display each word and it's length.Ans. str1 = input("Enter any String") x = str1.split() for i in x: print(i, "------", len(i))Q4. Write a program to accept a string and display string with capital letter of each word. for example, if input string is : welcome to my blog output string : Welcome To My BlogAns. str1 = input("Enter any String") x = str1.split() str2 = " " for i in x: str2 = str2 + " " + i.capitalize() print(str2)Q5. What is split() function in String?Ans. split() function split or break the string into multiple substring at specified separator.Q6. Write the output of the following: a = "Mummy?Papa?Brother?Sister?Uncle" print(a.split()) print(a.split('?') print(a.split('?',1) print(a.split('?',3) print(a.split('?',10) print(a.split('?',-1)Ans. ['Mummy?Papa?Brother?Sister?Uncle'] ['Mummy', 'Papa', 'Brother', 'Sister', 'Uncle'] ['Mummy', 'Papa?Brother?Sister?Uncle'] ['Mummy', 'Papa', 'Brother', 'Sister?Uncle'] ['Mummy', 'Papa', 'Brother', 'Sister', 'Uncle'] ['Mummy', 'Papa', 'Brother', 'Sister', 'Uncle']Q7. Write a program to replace all the word 'do' with 'done' in the following string. str1 = "I do you do and we all will do"Ans. str1 = "I do you do and we all will do" print(str1.replace('do','done'))Q8. Write the output of the following. str1 = "I went to Auli" print(str1.replace("Auli", "Leh")) print(str1)Ans. I went to Leh I went to AuliQ9. What is the purpose of find() function in string?Ans. find() function will return the first occurrence of substring in main string.Q10. Write the output of the following: str1 = "Welcome to my Blog" print(str1.find('o')) print(str1.find('o',3)) print(str1.find('o',7)) print(str1.find('o',7,10))Ans. 4 4 9 9

Practice Questions of String in Python – Test 10
Q1. Accept a string and display in reverse order.
Ans.
str = input("Enter any String")
print(str[: : -1])Q2. Write a program to accept a string and display 20 times.
Ans.
str = input("Enter any String")
for i in range(20):
print(str)
Q3. Write a program to accept a string in python and display the entire string in upper case.
Ans.
str = input("Enter any String")
print(str.upper())Q4. Write a program to accept a string and display last three characters of the string.
Ans.
str = input("Enter any String")
print(str[-3 : : 1])Q5. Write a program to accept a string in python and display the entire string in lower case.
Ans.
str = input("Enter any String")
print(str.lower())Q6. Accept a string and display the entire string with first and last character in upper case.
Ans.
str = input("Enter any String")
print(str[0].upper() + str[1:-1] + str[-1].upper())Q7. Write a program to accept a string and display first three characters of the string.
Ans.
str = input("Enter any String")
print(str[0:3])Q8. Write a function in python which accept a string as argument and display total number of vowels.
Ans.
def vowcount(str):
v=0
for i in range(len(str)):
if str[i] in "aeiouAEIOU":
v = v +1
print("Total number of vowels are ", v)Q9. Write a function in python which accept a string as argument and display total number of lower case characters.
Ans.
def lowercount(str):
l=0
for i in range(len(str)):
if str[i].islower( ):
l = l +1
print("Total number of lower case are ", l)Q10. Write a function in python which accept a string as argument and display total number of digits.
Ans.
def digitcount(str):
d=0
for i in range(len(str)):
if str[i].isdigit( ):
d = d +1
print("Total number of digits are ", d)

I do not who are you people but really you are doing Hard work and Good work for the society. Good Luck.
Thankyou so much
Great work Very beneficial for students
Thankyou so much.
There’s a problem in Test 2 Q.(c); the given code will throw an error coz string replication is done with one string value and one int value
The correct code for the given output should be :-
str = “MyBLog”
for i in range (len(str)):
print(str[i]*i)
Thankyou Aman for your feedback.
Great Work thank you so much
Thank you 😊
Really very good question for interview..love u🥰
realy nice i love your effort for us