Python/MCQ on Python String Set 1 Sample Test,Sample questions

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

1.List

2.String

3.Dictionary

4.None of the above


Question:
 Python allows _____________ operations on string data type.

1.Concatenation

2.Membership

3.Slicing

4.Slicing


Question:
 str[5 : 11] will return ___________ character

1.5

2.6

3.11

4.None of the above


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

1.5

2.3

3.6

4.7


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

1.Error in Index

2.Index out of range in string

3.IndexError

4.None of the above


Question:
 What we call the following:


	

1.Escape Sequence

2.Special Character

3.Don’t have any common term

4.Keyword


Question:
 Which operator is used for string concatenation?

1.*

2.//

3.+

4.-


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

1.1

2.2

3.3

4.4


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

1.ABC

2.A BC

3. A B C

4.Error


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

1.L e a r n

2.Error

3.Infinite Loop

4.Learn


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

1. S TR

2.STR

3.S T R

4.S T R


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

1.False

2.True

3.Error

4.None of the above


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

1.[‘a’, ‘b’, ‘c’, ‘disae’]

2.[‘a’, ‘b’, ‘cisadisae’]

3. [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

4.None of the above


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

1.True

2.False

3.Error

4.None of the above


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

1. String

2.List

3.Tuple

4.Dictionary


Question:
Characters in a string can be _________ enclosed in quotes.

1.Digits

2.white space

3.letter

4.All the above


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

1.mutable

2.immutable

3.reversible

4.None of the above


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

1.Indexing

2.Replication

3.Concatenation

4.None of the above


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

1.0

2.1

3.-1

4.Error


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

1.2

2.3

3.1

4.None of the above


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

1.5

2.6

3.7

4.8


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

1.space

2.colon

3.semi colon

4.None of the above


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

1.ValueError

2. SyntaxError

3. IndexError

4.Error


Question:
Index value in String should be of type ________________

1.Float

2.Integer

3.String

4.Boolean


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

1.0

2.1

3.-1

4.Error


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

1. index( )

2.endswith( )

3. startswith( )

4.count( )


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

1.length( )

2.len( )

3. strlen( )

4.slen( )


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

1.String

2.List

3.Tuple

4.Dictionary


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

1.1

2.2

3.3

4.4


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

1.AnD*&

2.AnD&*

3. aNd&*

4.Error


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

1. Starting index

2.Ending index

3.Step Size

4.None of the above


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

1.List

2.Tuple

3.Dictionary

4.None of the above


Question:
str[11 : 5] will return _________

1.empty string

2.complete string

3. string of six characters

4.None of the above


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

1. from left

2.from right

3.from middle

4.None of the above


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

1.for loop only

2.while loop only

3.both of the above

4.conditional statement


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

1.2

2.3

3.4

4.-2


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

1.SyntaxError

2.ValueError

3.. IndexErro

4.. TypeError


Question:
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”

1.‘t’

2.‘ ‘

3. ‘o’

4. ‘t’


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

1. print( )

2. lower( )

3. upper( )

4.None of the above


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

1.print( )

2.lower( )

3.upper( )

4.None of the above


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

1.find( )

2.index( )

3.count( )

4.All the above


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

1.strip( )

2.lstrip( )

3. rstrip( )

4.Lstrip( )


Question:
Which of the following function return the integer value?

1.lower( )

2. upper( )

3.islower( )

4.find( )


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

1.asc( )

2.ord( )

3.asci( )

4. ascii( )


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

1. index( )

2.. find( )

3.Both of the above

4.None of the above


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

1.swapcase( )

2.upper( )

3.title( )

4.capitalize( )


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

1. islower( )

2. islower( )

3.Islower( )

4. islower( )


Question:
Which of the following is a mapping data type?

1.String

2.List

3.Tuple

4.Dictionary


Question:
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.

1.str1[: : k]

2.str1[n : m+1 : k]

3.str1[n : m : k ]

4.str1[m : n : k ]


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

1. partition( )

2.isupper( )

3.lower( )

4.swapcases( )


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

1.length( )

2.find( )

3. endswith( )

4.split( )


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

1. a only

2.b only

3.both a and b

4.None of the above


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

1.print(“Computer” , ” “, “Computer”)

2.print(“Computer”,”Computer”)

3.print(“Computer” **2)

4.print(“Computer” * 2)


Question:
Which of the following will return reverse string str1?

1.str1[ : : -1]

2.str1[: : 1]

3.str1[: -1 : -1 ]

4.None of the above


Question:
Which of the function returns Boolean value?

1. find( )

2.index( )

3.endwith( )

4.endswith( )


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

1./

2.//

3.**

4.*


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

1.1

2.2

3.3

4.4


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

1.False

2.True

3.Error

4.None of the above


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

1.1

2.2

3.3

4.4


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

1.1

2.2

3.5

4.6


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

1.Welcome to blog

2.Welcome to blog

3.Welcome to blog

4.Error


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

1.Welcome to “my” blog

2.Welcome to ”my” blog

3.Error

4.None of the above


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

1.Error

2.@@@@@@

3.@ @@ @@@

4.@ @ @ @ @ @


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

1.True

2.False

3.Error

4.None of the above


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

1.Error

2.TypeError

3.A B C D E

4.ABCDE


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

1.Error

2.TypeError

3.A B C D E

4.ABCDE


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

1.g$o$l$b$

2.g$o$l$

3.Error

4.None of the above


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

1.6

2.7

3.8

4.Error


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

1. Weacome

2.Error

3. aWelcome

4.Welcomea


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

1.0

2.1

3.Error

4.None of the above


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

1.True

2.False

3.yes

4.Error


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

1.Bloga

2.aBlog

3.Blog

4.a


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

1.#12345

2.#12345#

3.1#2#3#4#5

4.1#2#3#4#5#


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

1. t

2.h

3.th

4.Error


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

1.5

2.6

3.7

4.8


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

1.NO

2.True

3.false

4.Error


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

1.Hello World!’

2. ‘Hell* W*rld!’

3.‘Hello W*rld!’

4.Error


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

1. HELLO world

2.Hello World

3.Hello world

4.HeLlO WoRlD


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

1.(‘India ‘, ‘is’, ‘ a Great is Country’)

2.(‘India ‘, ‘is’, ‘a Great’, ‘is’, ‘Country’)

3.(‘India ‘, ‘is’, ‘ a Great Country’)

4.Error


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

1.True

2.False

3.yes

4.No


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

1.p@y@t@h@o@n’

2.‘p@y@t@h@o@n@’

3.@p@y@t@h@o@n@’

4.‘@


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

1.‘p@y@t@h@o@n’

2.p@y@t@h@o@n@’

3.‘@p@y@t@h@o@n@’

4.@’


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

1. 2 3

2.23

3.SyntaxError

4.TypeError


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

1.We to my b ok

2.We to myb ok

3.Weto my b ok

4.None of the above


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

1.p t o

2.p y t h o n

3.y h n

4.p y t h


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

1.[‘a’, ‘b’, ‘c’, ‘disae’]

2.[‘a’, ‘b’, ‘cisadisae’]

3.[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

4.None of the above


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

1.True

2.False

3.yes

4.No


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

1.A#B#C#D#E

2.A?B?C?D?E

3.Can not replace as Strings are immutable

4.Error


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

1.[‘A’, ‘B’, ‘C#D#E’]

2.[‘A#’, ‘B#’, ‘C#D#E’]

3. [‘A’, ‘B’, ‘C’ , ‘D’ , ‘E’]

4.Error


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

1.3

2.12

3.11

4.3,11


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

1.9

2.Error

3.3

4.6


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

1.TRUE

2.True

3.FLAS

4.Error


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

1. 0

2.-1

3.1

4.Error


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

1. is a

2.a

3.is

4.i


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

1.Slicer

2.Slicing

3.Membership

4.None of the above


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Python Practice Papers
  53. python mcq question and answer
  54. Test
Learn MCQ on Python String Set 1,Learn Python Objetive choice questions and answers,Python Multiple choice questions and answers,Python objective, Python questions , Python answers,Python MCQs questions and answer
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!