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)
Q9. Write the output of the following. str1 = "Welcome \tto my Blog" str2 = "Welcome to\n my \tBlog print(str1) print(str2)
Q10. Write the output of the following.
str1 = “”” Welcome to my
blog.
This is for
Class X”””
print(str1)
Practice Questions of String in Python – Test 2
Q1. Write the output of following code-
a) str="hello" print(str[:3])
b) str=’My Blog’
a=’ ‘
for i in range(len(str)):
a+=str[i]
print(a)
c)Â Â Â Â Â Â Â Â Â Â Â Â Â str='MyBLog'Â Â Â Â Â Â Â Â Â Â Â Â Â Â a=' ' Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â for i in range(len(str)): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â print(i * str[i])
d) s='My' s1='Blog' s2=s[:1]+s1[len(s1)-1:] print(s2)
e) print(“My”+’Blog’ * 2)
f) print(“My” *3 + “Blog” +’7′)
g) for i in range(2,7,2): print(i * '2')
h) for i in range(3,12, 2): print("a".upper())
i) for i in range(3,12,13): print("a".upper)
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))
Practice Questions of String in Python – Test 3
Q1. Write a code to create empty string 'str1' Q2. What do you mean by traversing a string? Q3. What is the index value of first element of a string? Q4. What is the index value of last element of a string? Q5. If the length of the string is 10 then what would be the positive index value of last element? Q6. If the length of string is 9, what would be the index value of middle element? Q7. Index value of a string can be in float. (T/F) Q8. What type of error is returned by following statement, if the length of string 'str1' is 10. print(str1[13]) Q9. Write the output of the following: str1 = "Welcome to my Blog" a. print(str1[-1]) b. print(str1[9]) Q10. Write a code to assign a string "Hello World"' to a string variable named "str1".
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 Q2. Write a program to display each character of the following string in separate line using 'while' loop. str1 = Welcome to My Blog Q3. Index value of string "str1" varies from 0 to len(str1)-1. (T/F) Q4. Write the positive and negative index value of 'B' in the following string. "Welcome to my Blog" Q5. What do you mean by concatenation of string? Q6. Which of the following is an example of concatenation? a. 6 + 3 b. '6' + '3' c. 'a' + 'b' + 'c' Q7. Write a program to count the length of string without using inbuilt function. 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 = '#') Q9. Write the output of the following statement. str1 = "Amit" for i in str1: print(i) print(i, end =' ') 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 = '#')
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' Q3. The ___________ operator join the string. Q4. What type of error is shown by following code? >>> 2 + '3' Q5. Which operator is used to replicate string? Q6. Write the output of the following. >>> 'A' * 3 Q7. Write the output of the following: for i in range(2,5,2): print(i * '@') Q8. 'in' or 'not in' are the _________ operator Q9. Write the output of the following >>> 'h' in 'Hindi' >>>'i' in 'Hindi' Q10. Write the output of the following for i in "Amit": print(i in "Amit")
Practice Questions of String in Python – Test 6
Q1. Write the output of the following >>>"string" in "substring" >>>"string" not in "substring" Q2. Write the output of the following: >>>'tie' == 'ties' >>>"Amit" != "Amitabh" >>>"amit" > "Amitabh" Q3. Write the full form of ASCII Q4. Write the ASCII value of 'A' and 'a'. Q5. String Slicing is used to fetch substring from a string. (T/F) Q6. 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]) Q7. Strings are mutable.(T/F) Q8. Write the output of the following >>>str1 = "Anita" >>>str1[1] = 'm' >>>print(str1) Q9. Name any two built in function associated with string. Q10. Which function of string return the numerical value?
Practice Questions of String in Python – Test 7
Q1. What is the value returned by find() function for an unsuccessful search? Q2. isalpha() returns True if the string contains only alphabet.(T/F) Q3. 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. Q4. Write a program to accept string and display total number of alphabets. 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 : 5 Q6. Write the output of the following: >>>a = 123 >>>b = "123" >>>b.isdigit() >>>a.isdigit() Q7. What is the difference between lower() and islower()? Q8. Write a program to accept a string and convert it into lowercase. Q9. Write a program to count the number of lowercase and uppercase character in a string accepted from the user. Q10. Write the output of the following: >>>s = "My blog" >>>s.upper() >>>s.lower() >>>s.islower() >>>s.isupper() >>>s.isalpha() >>>s.isdigit()
Practice Questions of String in Python – Test 8
Q1. What is lstrip () function in 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())) Q3. 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())) Q4. Write the output of the following. >>>str1 = "Welcome to my Blog" >>>print(str1.rstrip('og')) >>>print(str1.lstrip('We')) >>>print(str1.strip('Welog)) Q5. Write the output of the following. >>>print(len(str1.rstrip('og'))) >>>print(len(str1.lstrip('We'))) >>>print(len(str1.strip('Welog))) Q6. isspace() returns True if the string contain only spaces (T/F) Q7. Write the output of the following >>>s1 = " " >>>s2 = " Amit" >>>print(s1.isspace()) >>>print(s2.isspace()) Q8. Define the following function with example a. istitle() b.swapcase()
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)) Q2. Write the output of the following. >>>str1 = "Welcome to my Blog" >>>x = str1.split() >>>print(x) Q3. Write a program to accept a string and display each word and it's length. 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 Blog Q5. What is split() function in String? 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) 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" Q8. Write the output of the following. str1 = "I went to Auli" print(str1.replace("Auli", "Leh")) print(str1) Q9. What is the purpose of find() function in 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))
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