Python — Learn

MCQ on Python String Set 1

Review each question and reveal answers to strengthen your understanding

1 Following is an example of ___________________ sv = “csiplearninghub.com”
✅ Correct Answer: 1
2 Write the output of the following. a = "Blog" a ='a' print(a)
✅ Correct Answer: 4
3 Write the output of the following: a="We to my b ok" print(a)
✅ Correct Answer: 1
4 Write the output of the following code : a= "Welcome to "my" blog" print(a)
✅ Correct Answer: 1
5 Write the output of the following code : a= "Welcome to blog" print(a)
✅ Correct Answer: 1
6 Write the output of the following code : str = "Welcome" str[2] = 'a' print(str)
✅ Correct Answer: 2
7 Write the output of the following code : str = "Welcome" l=len(str) print(l)
✅ Correct Answer: 2
8 What we call the following:
✅ Correct Answer: 1
9 Write the output of the following code : a = '''A B C''' print(a)
✅ Correct Answer: 3
10 What is the index value of ‘i’ in string “Learning”
✅ Correct Answer: 1
11 Index value in String should be of type ________________
✅ Correct Answer: 2
12 What type of error is returned by the following : str = "Learning" print(str[10])
✅ Correct Answer: 3
13 Which character will have same index value when you access elements from the beginning and from the end(ignore the negative sign) in the following string. s = “Welcome to my blog”
✅ Correct Answer: 3
14 Which of the following statement is correct in accessing each element of string?a) a="Learning" while(i): print(i) b) a="Learning" for i in a: print(i)
✅ Correct Answer: 2
15 Name the function which is used to find length of string.
✅ Correct Answer: 2
16 Write the output of the following code : for i in "STR": print(i)
✅ Correct Answer: 4
17 Write the output of the following code : a="Learn" while(a): print(a)
✅ Correct Answer: 3
18 Which operator is used with integers as well as with strings?
✅ Correct Answer: 4
19 Write the output of the following: 2 + '3'
✅ Correct Answer: 4
20 Which operator is used for string concatenation?
✅ Correct Answer: 3
21 Write the output of the following code : for i in (1,2,3): print("@" * i)
✅ Correct Answer: 3
22 How many operators are used in the following statement? 7 + 4 * 8 // 2 ** 2 - 6 / 1
✅ Correct Answer: 2
23 Write the output of the following code : s="blog" for i in range(-1,-len(s),-1): print(s[i],end="$")
✅ Correct Answer: 2
24 Write the output of the following code : s= "str" s1 = "string" print(s1 in s)
✅ Correct Answer: 2
25 Write the output of the following code : s= "str" Write the output of the following code : for i in range(65,70): print(chr(i))
✅ Correct Answer: 1
26 Write the output of the following code : s= "str" Write the output of the following code : for i in range(65,70): print(chr(i))
✅ Correct Answer: 1
27 Write the output of the following: print(“A#B#C#D#E”.split(“#”,2))
✅ Correct Answer: 1
28 Write the output of the following: print(“A#B#C#D#E”.replace(“#”,”?”))
✅ Correct Answer: 2
29 Write the output of the following: print(“I love my Country”.find(“o”,4))
✅ Correct Answer: 3
30 Write the output of the following. print(‘#’.join(“12345”))
✅ Correct Answer: 3
31 Which of the following is not a String built in functions?
✅ Correct Answer: 4
32 Write the output of the following: print(len("\\\///"))
✅ Correct Answer: 4
33 Which of the following function returns the ASCII/Unicode value character?
✅ Correct Answer: 2
34 Which of the following statements will also return the same result as given statement? print(“Computer” + “Computer”)
✅ Correct Answer: 4
35 Write the output of the following: for i in range(len("python"),12,2): print("python"[i-6])
✅ Correct Answer: 1
36 Which of the following is a mapping data type?
✅ Correct Answer: 4
37 A _____________ can be created by enclosing one or more characters in single, double or triple quote
✅ Correct Answer: 1
38 Characters in a string can be _________ enclosed in quotes.
✅ Correct Answer: 3
39 Each individual character in a string can be accessed using a technique called _____
✅ Correct Answer: 1
40 If we give index value out of the range then we get an ___
✅ Correct Answer: 2
41 The index of the first character ____________ on the string is 0
✅ Correct Answer: 1
42 What type of error is returned by statement : >>> str[1.5]
✅ Correct Answer: 4
43 Write the output of the following. str = “python” print(str[2+1])
✅ Correct Answer: 1
44 Content of string can not be changed, it means that string is
✅ Correct Answer: 2
45 Python allows _____________ operations on string data type.
✅ Correct Answer: 4
46 _________ method is used to access some part of a string or substring.>>> str1 = ‘Hello World!’ >>> ‘W’ in str1
✅ Correct Answer: 2
47 str[5 : 11] will return ___________ character
✅ Correct Answer: 2
48 str[11 : 5] will return _________
✅ Correct Answer: 1
49 Slice operation can also take a third parameter that specifies the _____
✅ Correct Answer: 3
50 Which of the following is correct slicing operation to extract every kth character from the string str1 starting from n and ending at m-1.
✅ Correct Answer: 3
51 Which of the following will return reverse string str1?
✅ Correct Answer: 1
52 We can access each character of a string or traverse a string using ___
✅ Correct Answer: 3
53 Which of the following function returns the string with first letter of every word in the string in uppercase and rest in lowercase?
✅ Correct Answer: 3
54 Write the output of the following: s = ” Hello” print(s.find(‘a’))
✅ Correct Answer: 2
55 What index value is returned by the following code? s = “Hello” print(s.find(‘l’))
✅ Correct Answer: 1
56 Following code will return ? s = “Hello” print(s.count(‘l’,2,5))
✅ Correct Answer: 1
57 Name a function which is same as find() but raises an exception if the substring is not present in the given string.
✅ Correct Answer: 1
58 Write the output of the following. >>> str1 = ‘Hello World! Hello >>> str1.index(‘Hee’)
✅ Correct Answer: 3
59 Write the output of the following. >>> str1 = ‘Hello World!’ >>> str1.endswith(‘World!’)
✅ Correct Answer: 1
60 Write the output of the following. s = “hello 123” print(s.islower())
✅ Correct Answer: 2
61 Write the output of the following: >>> str1 = 'hello WORLD!' >>> str1.title()
✅ Correct Answer: 2
62 Write the output of the following : >>> str1 = ‘HelloWorld!!’ >>> str1.isalnum()
✅ Correct Answer: 1
63 Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello',12,25)
✅ Correct Answer: 1
64 Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello')
✅ Correct Answer: 3
65 Write the output of the following : print("Absbcbcgdbc".count("b",4))
✅ Correct Answer: 2
66 Write the output of the following : print("Absbcbcgdbc".find("b",5))
✅ Correct Answer: 3
67 Which of the following function returns the index value of first occurrence of substring occurring in the given string.
✅ Correct Answer: 3
68 find( ) function returns ___________ if the substring is not present in the given string
✅ Correct Answer: 3
69 index( ) function returns _______________ if the substring is not present in the given string
✅ Correct Answer: 4
70 >>> “Hey!”.endswith(‘!’) will return ______
✅ Correct Answer: 1
71 Which of the function returns Boolean value?
✅ Correct Answer: 4
72 Write the output of the following: >>> str1 = 'String MCQ' >>> str1.startswith('Str')
✅ Correct Answer: 1
73 Write the output of the following: print("Welcome-Python".isalnum())
✅ Correct Answer: 2
74 Write the output of the following: print(str("WelcomePython".isalnum()).upper())
✅ Correct Answer: 1
75 Write the output of the following: >>> str1 = 'hello ??' >>> str1.islower( )
✅ Correct Answer: 2
76 Which of the following function returns True if the string is non-empty and has all uppercase alphabets.
✅ Correct Answer: 2
77 Write the output of the following: >>> str1 = 'Hello World!' >>> str1.replace('o' , '*')
✅ Correct Answer: 2
78 Write the output of the following: >>> str1 = 'India is a Great is Country' >>> str1.partition('is')
✅ Correct Answer: 1
79 Write the output of the following: str = "Amit is a is a" s = str.partition('is') print(s[1])
✅ Correct Answer: 2
80 partition( ) function of string in python return the result in the form of ____
✅ Correct Answer: 3
81 partition() function divides the main string into ________ substring.
✅ Correct Answer: 3
82 split( ) function returns the _______________of words delimited by the specified substring.
✅ Correct Answer: 1
83 If no delimiter is given in split( ) function then words are separated by ____
✅ Correct Answer: 1
84 Write the output of the following: "python".join("@")
✅ Correct Answer: 4
85 Write the output of the following: "@".join("python")
✅ Correct Answer: 1
86 Write the output of the following: >>> len(" python".lstrip()) #2 spaces are given before "python"
✅ Correct Answer: 2
87 Which of the following function removes only leading spaces from the string?
✅ Correct Answer: 2
88 Which of the following function can take maximum three arguments/parameters?
✅ Correct Answer: 4
89 Which of the following function return the integer value?
✅ Correct Answer: 4
90 Which of the following is not an inbuilt function of string?
✅ Correct Answer: 1
91 Which function in the following statement will execute first? print("amit".lower().upper())
✅ Correct Answer: 1
92 Which function in the following statement will execute last? print("amit".lower().upper())
✅ Correct Answer: 4
93 Write the output of the following: print('aisabisacisadisae'.split('isa',3))
✅ Correct Answer: 1
94 Write the output of the following: print('aisabisacisadisae'.split('isa'))
✅ Correct Answer: 3
95 print(“aNd&*”.swapcase()) will display _
✅ Correct Answer: 2
Back to All Quizzes