Python MCQ Quiz Hub

MCQ on Python String Set 1

Choose a topic to test your knowledge and improve your Python skills

Following is an example of ___________________ sv = “csiplearninghub.com”





✅ Correct Answer: 1

Write the output of the following. a = "Blog" a ='a' print(a)





✅ Correct Answer: 4

Write the output of the following: a="We to my b ok" print(a)





✅ Correct Answer: 1

Write the output of the following code : a= "Welcome to "my" blog" print(a)





✅ Correct Answer: 1

Write the output of the following code : a= "Welcome to blog" print(a)





✅ Correct Answer: 1

Write the output of the following code : str = "Welcome" str[2] = 'a' print(str)





✅ Correct Answer: 2

Write the output of the following code : str = "Welcome" l=len(str) print(l)





✅ Correct Answer: 2

What we call the following:





✅ Correct Answer: 1

Write the output of the following code : a = '''A B C''' print(a)





✅ Correct Answer: 3

What is the index value of ‘i’ in string “Learning”





✅ Correct Answer: 1

Index value in String should be of type ________________





✅ Correct Answer: 2

What type of error is returned by the following : str = "Learning" print(str[10])





✅ Correct Answer: 3

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

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

Name the function which is used to find length of string.





✅ Correct Answer: 2

Write the output of the following code : for i in "STR": print(i)





✅ Correct Answer: 4

Write the output of the following code : a="Learn" while(a): print(a)





✅ Correct Answer: 3

Which operator is used with integers as well as with strings?





✅ Correct Answer: 4

Write the output of the following: 2 + '3'





✅ Correct Answer: 4

Which operator is used for string concatenation?





✅ Correct Answer: 3

Write the output of the following code : for i in (1,2,3): print("@" * i)





✅ Correct Answer: 3

How many operators are used in the following statement? 7 + 4 * 8 // 2 ** 2 - 6 / 1





✅ Correct Answer: 2

Write the output of the following code : s="blog" for i in range(-1,-len(s),-1): print(s[i],end="$")





✅ Correct Answer: 2

Write the output of the following code : s= "str" s1 = "string" print(s1 in s)





✅ Correct Answer: 2

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

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

Write the output of the following: print(“A#B#C#D#E”.split(“#”,2))





✅ Correct Answer: 1

Write the output of the following: print(“A#B#C#D#E”.replace(“#”,”?”))





✅ Correct Answer: 2

Write the output of the following: print(“I love my Country”.find(“o”,4))





✅ Correct Answer: 3

Write the output of the following. print(‘#’.join(“12345”))





✅ Correct Answer: 3

Which of the following is not a String built in functions?





✅ Correct Answer: 4

Write the output of the following: print(len("\\\///"))





✅ Correct Answer: 4

Which of the following function returns the ASCII/Unicode value character?





✅ Correct Answer: 2

Which of the following statements will also return the same result as given statement? print(“Computer” + “Computer”)





✅ Correct Answer: 4

Write the output of the following: for i in range(len("python"),12,2): print("python"[i-6])





✅ Correct Answer: 1

Which of the following is a mapping data type?





✅ Correct Answer: 4

A _____________ can be created by enclosing one or more characters in single, double or triple quote





✅ Correct Answer: 1

Characters in a string can be _________ enclosed in quotes.





✅ Correct Answer: 3

Each individual character in a string can be accessed using a technique called _____





✅ Correct Answer: 1

If we give index value out of the range then we get an ___





✅ Correct Answer: 2

The index of the first character ____________ on the string is 0





✅ Correct Answer: 1

What type of error is returned by statement : >>> str[1.5]





✅ Correct Answer: 4

Write the output of the following. str = “python” print(str[2+1])





✅ Correct Answer: 1

Content of string can not be changed, it means that string is





✅ Correct Answer: 2

Python allows _____________ operations on string data type.





✅ Correct Answer: 4

_________ method is used to access some part of a string or substring.>>> str1 = ‘Hello World!’ >>> ‘W’ in str1





✅ Correct Answer: 2

str[5 : 11] will return ___________ character





✅ Correct Answer: 2

str[11 : 5] will return _________





✅ Correct Answer: 1

Slice operation can also take a third parameter that specifies the _____





✅ Correct Answer: 3

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

Which of the following will return reverse string str1?





✅ Correct Answer: 1

We can access each character of a string or traverse a string using ___





✅ Correct Answer: 3

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

Write the output of the following: s = ” Hello” print(s.find(‘a’))





✅ Correct Answer: 2

What index value is returned by the following code? s = “Hello” print(s.find(‘l’))





✅ Correct Answer: 1

Following code will return ? s = “Hello” print(s.count(‘l’,2,5))





✅ Correct Answer: 1

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

Write the output of the following. >>> str1 = ‘Hello World! Hello >>> str1.index(‘Hee’)





✅ Correct Answer: 3

Write the output of the following. >>> str1 = ‘Hello World!’ >>> str1.endswith(‘World!’)





✅ Correct Answer: 1

Write the output of the following. s = “hello 123” print(s.islower())





✅ Correct Answer: 2

Write the output of the following: >>> str1 = 'hello WORLD!' >>> str1.title()





✅ Correct Answer: 2

Write the output of the following : >>> str1 = ‘HelloWorld!!’ >>> str1.isalnum()





✅ Correct Answer: 1

Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello',12,25)





✅ Correct Answer: 1

Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello')





✅ Correct Answer: 3

Write the output of the following : print("Absbcbcgdbc".count("b",4))





✅ Correct Answer: 2

Write the output of the following : print("Absbcbcgdbc".find("b",5))





✅ Correct Answer: 3

Which of the following function returns the index value of first occurrence of substring occurring in the given string.





✅ Correct Answer: 3

find( ) function returns ___________ if the substring is not present in the given string





✅ Correct Answer: 3

index( ) function returns _______________ if the substring is not present in the given string





✅ Correct Answer: 4

>>> “Hey!”.endswith(‘!’) will return ______





✅ Correct Answer: 1

Which of the function returns Boolean value?





✅ Correct Answer: 4

Write the output of the following: >>> str1 = 'String MCQ' >>> str1.startswith('Str')





✅ Correct Answer: 1

Write the output of the following: print("Welcome-Python".isalnum())





✅ Correct Answer: 2

Write the output of the following: print(str("WelcomePython".isalnum()).upper())





✅ Correct Answer: 1

Write the output of the following: >>> str1 = 'hello ??' >>> str1.islower( )





✅ Correct Answer: 2

Which of the following function returns True if the string is non-empty and has all uppercase alphabets.





✅ Correct Answer: 2

Write the output of the following: >>> str1 = 'Hello World!' >>> str1.replace('o' , '*')





✅ Correct Answer: 2

Write the output of the following: >>> str1 = 'India is a Great is Country' >>> str1.partition('is')





✅ Correct Answer: 1

Write the output of the following: str = "Amit is a is a" s = str.partition('is') print(s[1])





✅ Correct Answer: 2

partition( ) function of string in python return the result in the form of ____





✅ Correct Answer: 3

partition() function divides the main string into ________ substring.





✅ Correct Answer: 3

split( ) function returns the _______________of words delimited by the specified substring.





✅ Correct Answer: 1

If no delimiter is given in split( ) function then words are separated by ____





✅ Correct Answer: 1

Write the output of the following: "python".join("@")





✅ Correct Answer: 4

Write the output of the following: "@".join("python")





✅ Correct Answer: 1

Write the output of the following: >>> len(" python".lstrip()) #2 spaces are given before "python"





✅ Correct Answer: 2

Which of the following function removes only leading spaces from the string?





✅ Correct Answer: 2

Which of the following function can take maximum three arguments/parameters?





✅ Correct Answer: 4

Which of the following function return the integer value?





✅ Correct Answer: 4

Which of the following is not an inbuilt function of string?





✅ Correct Answer: 1

Which function in the following statement will execute first? print("amit".lower().upper())





✅ Correct Answer: 1

Which function in the following statement will execute last? print("amit".lower().upper())





✅ Correct Answer: 4

Write the output of the following: print('aisabisacisadisae'.split('isa',3))





✅ Correct Answer: 1

Write the output of the following: print('aisabisacisadisae'.split('isa'))





✅ Correct Answer: 3

print(“aNd&*”.swapcase()) will display _





✅ Correct Answer: 2