Python MCQ Quiz Hub

MCQ on Python String Set 1

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

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




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




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




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




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




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




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




8. What we call the following:




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




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




11. Index value in String should be of type ________________




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




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”




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)




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




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




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




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




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




20. Which operator is used for string concatenation?




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




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




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




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




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))




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))




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




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




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




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




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




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




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




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




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




36. Which of the following is a mapping data type?




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




38. Characters in a string can be _________ enclosed in quotes.




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




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




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




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




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




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




45. Python allows _____________ operations on string data type.




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




47. str[5 : 11] will return ___________ character




48. str[11 : 5] will return _________




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




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.




51. Which of the following will return reverse string str1?




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




53. Which of the following function returns the string with first letter of every word in the string in uppercase and rest in lowercase?




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




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




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




57. Name a function which is same as find() but raises an exception if the substring is not present in the given string.




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




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




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




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




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




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




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




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




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




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




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




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




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




71. Which of the function returns Boolean value?




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




89. Which of the following function return the integer value?




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




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




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




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




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




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