Python/Python Mcq Set 5 Sample Test,Sample questions

Question:
 If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.

1. obj.__str__()

2.str(obj)

3.print obj

4. all of the mentioned


Question:
 Suppose s is “		World
”, what is s.strip()?

1. World

2. World

3. WORLD

4.World


Question:
 To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?

1. s[]

2.s.getitem(3)

3.s.__getitem__(3)

4.s.getItem(3)


Question:
 What will be the output of the following Python code?

>>>print("D", end = ' ')
>>>print("C", end = ' ')
>>>print("B", end = ' ')
>>>print("A", end = ' ')

1.DCBA

2. A, B, C, D

3. D C B A

4.D, C, B, A will be displayed on four lines


Question:
 What will be the output of the following Python code?

print("abc DEF".capitalize())

1.abc def

2.ABC DEF

3.Abc def

4. Abc Def


Question:
 What will be the output of the following Python code?

print(0xA + 0xB + 0xC)

1. 0xA0xB0xC

2.Error

3.0x22

4.33


Question:
 What will be the output of the following Python code?

x = (i for i in range(3))
for i in x:
    print(i)

1. 0 1 2

2.error

3. 0 1 2 0 1 2

4.none of the mentioned


Question:
 What will be the output of the following Python statement?(python 3.xx)

>>>print(format("Welcome", "10s"), end = '#')
>>>print(format(111, "4d"), end = '#')
>>>print(format(924.656, "3.2f"))

1.Welcome# 111#924.66

2.Welcome#111#924.66

3.Welcome#111#.66

4.Welcome # 111#924.66


Question:
Given a string example=”hello” what is the output of example.count(‘l’)?

1.2

2. 1

3.None

4.0


Question:
Say s=”hello” what will be the return value of type(s)?

1.int

2.bool

3.str

4.String


Question:
Suppose i is 5 and j is 4, i + j is same as ________

1. i.__add(j)

2. i.__add__(j)

3. i.__Add(j)

4.i.__ADD(j)


Question:
Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).

1. __345.355

2.___345.355

3.___345.355

4._____345.354


Question:
The format function, when applied on a string returns ______

1. Error

2. int

3.bool

4.str


Question:
The output of executing string.ascii_letters can also be achieved by:

1.string.ascii_lowercase_string.digits

2.string.ascii_lowercase+string.ascii_uppercase

3.string.letters

4.string.lowercase_string.uppercase


Question:
To check whether string s1 contains another string s2, use ____

1.s1.__contains__(s2)

2.s2 in s1

3.s1.contains(s2)

4.si.in(s2)


Question:
To concatenate two strings to a third what statements are applicable?

1. s3 = s1 . s2

2.s3 = s1.add(s2)

3.s3 = s1.__add__(s2)

4. s3 = s1 * s2


Question:
To return the length of string s what command do we execute?

1.s.__len__()

2. len(s)

3. size(s)

4.s.size()


Question:
What arithmetic operators cannot be used with strings?

1. +

2.*

3.–

4.all of the mentioned


Question:
What function do you use to read a string?

1.input(“Enter a string”)

2.eval(input(“Enter a string”))

3.enter(“Enter a string”)

4.eval(enter(“Enter a string”))


Question:
What is “Hello”.replace(“l”, “e”)?

1.Heeeo

2.Heelo

3.Heleo

4. None


Question:
What will be displayed by print(ord(‘b’) – ord(‘a’))?

1.0

2. 1

3. -1

4. 2


Question:
What will be the output of the “hello” +1+2+3?

1. hello123

2. hello

3.Error

4. hello6


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
for a[-1] in a:
    print(a[-1])

1.0 1 2 3

2.0 1 2 2

3. 3 3 3 3

4.error


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0])

1.0 1 2 3

2.0 1 2 2

3. 3 3 3 3

4.error


Question:
What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]
i = -2
for i not in a:
    print(i)
    i += 1

1. -2 -1

2.0

3. error

4.none of the mentioned


Question:
What will be the output of the following Python code snippet?

string = "my name is x"
for i in ' '.join(string.split()):
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x,

2.m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4.error


Question:
What will be the output of the following Python code?

>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]

1.olleh

2.hello

3.h

4.o


Question:
What will be the output of the following Python code?

>>>example = "helle"
>>>example.find("e")

1.Error

2. -1

3.1

4.0


Question:
What will be the output of the following Python code?

>>>example = "helle"
>>>example.rfind("e")

1.-1

2.4

3. 3

4.1


Question:
What will be the output of the following Python code?

>>>example = "snow world"
>>>example[3] = 's'
>>>print example

1. snow

2.snow world

3. Error

4.snos world


Question:
What will be the output of the following Python code?

>>>example = "snow world"
>>>print("%s" % example[4:7])

1.wo

2.world

3.sn

4.rl


Question:
What will be the output of the following Python code?

>>>example="helloworld"
>>>example[::-1].startswith("d")

1.dlrowolleh

2. True

3.-1

4.None


Question:
What will be the output of the following Python code?

>>>max("what are you")

1.error

2.u

3. t

4. Y


Question:
What will be the output of the following Python code?

>>>print (r"
hello")

1. a new line and hello

2. hello

3.the letter r and then hello

4.error


Question:
What will be the output of the following Python code?

>>>str1="helloworld"
>>>str1[::-1]

1. dlrowolleh

2.hello

3.world

4.helloworld


Question:
What will be the output of the following Python code?

for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

1.0 1 2 3 4 Here

2.0 1 2 3 4 5 Here

3.0 1 2 3 4

4.1 2 3 4 5


Question:
What will be the output of the following Python code?

print('*', "abcdef".center(7), '*')

1. * abcdef *

2.* abcdef *

3. *abcdef *

4. * abcdef*


Question:
What will be the output of the following Python code?

print('*', "abcdef".center(7), '*', sep='')

1.* abcdef *

2.* abcdef *

3. *abcdef *

4.* abcdef*


Question:
What will be the output of the following Python code?

print("abc. DEF".capitalize())

1.abc. def

2.ABC. DEF

3. Abc. def

4.Abc. Def


Question:
What will be the output of the following Python code?

print("abcdef".center())

1.cd

2.abcdef

3. error

4.none of the mentioned


Question:
What will be the output of the following Python code?

print("abcdef".center(0))

1. cd

2. abcdef

3. error

4.none of the mentioned


Question:
What will be the output of the following Python code?

string = "my name is x"
for i in string.split():
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x

2. m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4.error


Question:
What will be the output of the following Python code?

string = "my name is x"
for i in string:
    print (i, end=", ")

1.m, y, , n, a, m, e, , i, s, , x,

2.m, y, , n, a, m, e, , i, s, , x

3.my, name, is, x,

4. error


Question:
What will be the output of the following Python code?

x = (i for i in range(3))
for i in x:
    print(i)
for i in x:
    print(i)

1. 0 1 2

2.error

3.0 1 2 0 1 2

4.none of the mentioned


Question:
What will be the output of the following Python statement?

>>>"a"+"bc"

1.a

2.bc

3.bca

4.abc


Question:
What will be the output of the following Python statement?

>>>"abcd"[2:]

1. a

2.ab

3.cd

4.dc


Question:
What will be the output of the following Python statement?

>>>chr(ord('A'))

1.A

2. B

3. a

4. error


Question:
What will be the output of the following Python statement?

>>>print('new' 'line')

1. Error

2.Output equivalent to print ‘new line’

3.newline

4.new line


Question:
What will be the output of the following Python statement?

>>>print(chr(ord('b')+1))

1.a

2.b

3. c

4. A


Question:
Which of the following statement prints helloexample	est.txt?

1.print(“helloexample est.txt”)

2.print(“hello\example\test.txt”)

3.print(“hello”example”test.txt”)

4.print(“hello”example” est.txt”)


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
Search
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!