Posted on

Python Multiple Choice Questions and Answers

1. Python is a

a. High-level programming language

b. Low-level scripting language

c. Middle-level programming language

d. High-level scripting language

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) High-level scripting language[/bg_collapse]

2. What will be the output of this statement?

    i = 0  
    while i < 5:  
        print(i)  
        i += 1  
        if i == 3:  
            break  
    else:  
        print(0)  

a. 1 2 3

b. 3 2 1

c. 0 1 2

d. 0 1 2 3

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) 0 1 2 [/bg_collapse]

3. What will be the output of the following program?

    i = 1:  
    while True:  
        if i%3 == 0:  
            break  
        print(i)

a. 3 2 1

b. 1 2

c. 1 2 3

d. Invalid syntax

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) 1 2

Explanation: because, the declaration (i = 1:) is wrong.

[/bg_collapse]

4. Which one of the following has the same precedence level?

a. Subtraction and Division

b. Power and Division

c. Division and Multiplication

d. Division, Power, Multiplication, Addition and Subtraction

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) Division and Multiplication[/bg_collapse]

5. Which of the following operators is the correct option for power(xy)?

a. x**y

b. x ^ ^ y

c. x ^ * y

d. x ^ y

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (a) x**y

Explanation: To find the power of a number we use power operator a**b, i.e., 2**3=8.

[/bg_collapse]

6. Which of the following words cannot be used as a variable name in python?

a. var

b. _try_

c. _var

d. try

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) try

Explanation: because “try” is a keyword.

[/bg_collapse]

7. Which of the following is not a keyword in Python language?

a. with

b. raise

c.val

d. try

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) val

Explanation: because “val” is not a keyword in python.

[/bg_collapse]

8. What will be the output of this statement?

 >>>"x"+"yz"

a. xyz

b. x yz

c. x+yz

d. x

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) xyz

Explanation: The “+” operator is used to concatenation two strings.

[/bg_collapse]

9. Set members must not be hashable.

a. True

b. False

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (b)

Explanation: Set members must always be hashable.[/bg_collapse]

10. What will be the output of the following Python code?

x = 2
for i in range(x):
    x -= 2
    print (x)

a. 0

b. 0 1 2 3 4 …

c. 0 -2

d. error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) 0 -2

Explanation: The loop is entered twice.[/bg_collapse]

11. What is the maximum possible length of an identifier?

a. 79 characters

b. 35 characters

c. 22 characters

d. none of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) none of the mentioned

Explanation: Identifiers can be of any length.[/bg_collapse]

12. Which of the following declarations is incorrect?

a. _a = 4

b. __abc__ = 9

c. __a = 1

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) None of these[/bg_collapse]

13. What will be the output of this code?

    x = 1  
    while True:  
        if x % 5 = = 0:  
            break  
        print(x)   
        x + = 1  

a. 2 1

b. 0 3 1

c. error

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) error

Explanation: Syntax error, there should not be a space between + and =.

[/bg_collapse]

14. All keywords in Python are in

a. UPPER CASE

b. lower case

c. Capitalized

d. None of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) None of the mentioned

Explanation: True, False and None are capitalized while the others are in lower case.[/bg_collapse]

15. What will be the output of the following code?

>>> a=("NeuralBeast")*3
>>> a

a. Operator not valid for tuples

b. (‘NeuralBeastNeuralBeastNeuralBeast’)

c. (‘NeuralBeast’,’NeuralBeast’,’NeuralBeast’)

d. Syntax error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (b) (‘NeuralBeastNeuralBeastNeuralBeast’)

Explanation: Here (“NeuralBeast”) is a string not a tuple because there is no comma after the element.[/bg_collapse]

16. Which of the following cannot be a variable?

a. in

b. it

c. on

d. __init__

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (a) in

Explanation: in is a keyword.[/bg_collapse]

17. Which of the following functions is a built-in function in python language?

a. print()

b. val()

c. num()

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) print()

Explanation: The print() function is a built-in function in python that prints a value directly on the screen.

[/bg_collapse]

18. Which of the following precedence order is correct in Python?

a. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential

b. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential

c. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

d. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

Explanation: PEMDAS (similar to BODMAS).

[/bg_collapse]

19. What will be the output of this function?

round(12.638)

a. 13

b. 12.69

c. 12

d. 127

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) 13

Explanation: The round function is a built-in function in the Python language that round-off the value.

[/bg_collapse]

20. What will be the output of the following code?

    x = ['xy', 'yz']  
    for i in a:  
        i.upper()  
    print(a)  

a. [xyxy]

b. [‘XY’, ‘YZ’]

c. [‘xy’, ‘yz’]

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) [‘xy’, ‘yz’][/bg_collapse]

21. What will be the output of this statement?

>>> print(0xA + 0xB + 0xC) 

a. 0xA + 0xB + 0xC

b. 63

c. 33

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) 33

Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum of A, B and C is 33.

[/bg_collapse]

22. What will be the output of this code?

any([5>8, 6>3, 3>1])  

a. True

b. False

c. Invalid code

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (a) True[/bg_collapse]

23. What will be displayed by print(ord(‘b’) – ord(‘a’))?

a. 0

b. -1

c. 1

d. 2

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) 1

Explanation: ASCII value of b is one more than a. Hence the output of this code is 98-97, which is equal to 1.

[/bg_collapse]

24. Which of the following is not a declaration of the dictionary?

a. dict([[1,”A”],[2,”B”]])

b. {1,”A”,2”B”}

c. {1: ‘A’, 2: ‘B’}

d. { }

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (b) {1,”A”,2”B”}

Explanation: Option c is a set, not a dictionary.

[/bg_collapse]

25. Is Python case sensitive when dealing with identifiers?

a. machine dependent

b. yes

c. no

d. none of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (b) yes[/bg_collapse]

26. What will be the output of this function?

all([2,4,0,6]) 

a. 0

b. True

c. False

d. Invalid code

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) False

Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns a true value. Hence, the output of this “all([2,4,0,6])” function will be false.

[/bg_collapse]

27. What will be the output of the following code?

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

a. a

b. A

c. B

d. Error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (b) A[/bg_collapse]

28. What is the syntax of the following code for creating a frozenset?

>>> a=frozenset(set([5,6,7]))
>>> a

a. frozenset({5,6,7})

b. {5,6,7}

c. Error, not possible to convert set into frozenset

d. Syntax error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) frozenset({5,6,7})

Explanation: frozenset({5,6,7}) code is the correct syntax for creating a frozenset.

[/bg_collapse]

29. The format function, when it applied on a string returns

a. int

b. bool

c. str

d. Error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) str
Explanation: Format function will returns a string.[/bg_collapse]

30. Which of the following is correctly evaluated for the following function?

pow(x,y,z)

a. (x / y) * z

b. (x**y) / z

c. (x / y) / z

d. (x**y) % z

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) (x**y) % z[/bg_collapse]

31. What will be the output of the following code?

x = ['ab', 'cd']
for i in x:
    x.append(i.upper())
print(x)

a. [‘ab’, ‘cd’]

b. [‘ab’, ‘cd’, ‘AB’, ‘CD’]

c. [‘AB’, ‘CD’]

d. none of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) none of the mentioned

Explanation: The loop does not terminate as new elements are being added to the list in each iteration.

[/bg_collapse]

32. What will be the output of the following code?

print("D", end = ' ')
print("Z", end = ' ')
print("Y", end = ' ')
print("X", end = ' ')

a. XYZA

b. AZYX

c. A Z Y X

d. A, Z, Y, X will be displayed on four lines

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) A Z Y X[/bg_collapse]

33. Which one of the following has the same precedence level?

a. Multiplication, Division and Addition

b. Multiplication, Division, Addition and Subtraction

c. Addition and Multiplication

d. Addition and Subtraction

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) Addition and Subtraction

Explanation: “Addition and Subtraction” are at the same precedence level.

[/bg_collapse]

34. What will be the output of this statement?

    d = {0, 1, 2}  
    for x in d:  
        print(x) 

a. 0 1 2

b. {0, 1, 2} {0, 1, 2} {0, 1, 2}

c. Syntax_Error

d. None of these above

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (a) 0 1 2[/bg_collapse]

35. What will be the output of this code?

    import math  
    abs(math.sqrt(36))  

a. 6

b. -6

c. 6.0

d. Error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) 6.0

Explanation: This sqrt() function will prints the square of the value.

[/bg_collapse]

36. What will be the output of the following code?

x = 2
for i in range(x):
    x += 1
    print (x)

a. 3 4

b. 0 1

c. 0 1 2 3 4 …

d. 0 1 2 3

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) 3 4

Explanation: Variable x is incremented and printed twice.

[/bg_collapse]

37. Which of the following commands will create a list?

a. mylist = list([1, 2, 3])

b. mylist = []

c. mylist = list()

d. all of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (d) all of the mentioned[/bg_collapse]

38. Is the following Python code valid or not?

a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)

a. True

b. False

c. Syntax error for issuperset() method

d. Error, no method called issuperset() exists

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (b) False

Explanation: The method issubset() returns True if b is a proper subset of a.

[/bg_collapse]

39. What will be the output of the following code?

i = 5
while True:
    if i%0O11 == 0:
        break
    print(i)
    i += 1

a. 5 6

b. 5 6 7 8 9 10

c. 5 6 7 8

d. error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) 5 6 7 8

Explanation: here, 0O11 is an octal number.

[/bg_collapse]

40. What will be the output of this statement?

str1 = "neural"  
str2 = ":"  
str3 = "beast"  
print(str1[-1:])

a. n

b. l

c. neural

d. beast

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (b) l

Explanation: The output of this program is “l” because -1 corresponds to the last index.

[/bg_collapse]

41. Which of the following is true for variable names in Python?

a. underscore and ampersand are the only two special characters allowed

b. all private members must have leading and trailing underscores

c. unlimited length

d. none of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) unlimited length

Explanation: Variable names can be of any length.

[/bg_collapse]

42. Which of the following is the correct output of this program?

    x = 'abcd'  
    for i in range(len(x)):  
        x[i].upper()  
    print (x) 

a. bcd

b. ABCD

c. abcd

d. None of these

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (c) abcd[/bg_collapse]

43. What will be the output of the following code?

>>> a=(2,3,4)
>>> sum(a,3)

a. The method sum() doesn’t exist for tuples

b. Too many arguments for sum() method

c. 9

d. 12

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) 12

Explanation: In the above case, 3 is the starting value to which the sum of the tuple is added to.

[/bg_collapse]

44. Lambda is a statement.

a. True

b. False

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (b) False

Explanation: lambda is an anonymous function in Python.

[/bg_collapse]

45. Which of the following functions accepts only integers as arguments?

a. min()

b. ord()

c. chr()

d. any()

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) chr()

Explanation: The function chr() accepts only integers as arguments. The functions min() and max() can accept floating point as well as integer arguments. The function ord() accepts only strings.

[/bg_collapse]

46. What is the method inside the class in python language?

a. Function

b. Object

c. Argument

d. Attribute

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (a) Function

Explanation: In python function is also known as the method.

[/bg_collapse]

47. What will be the output of the following Python code?

>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}

a. {8,10}

b. {8, 2, 10, 4, 6}

c. {2,4,6}

d. Error, set comprehensions aren’t allowed

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (b) {8, 2, 10, 4, 6}

Explanation: Set comprehensions are allowed.

[/bg_collapse]

48. What will be the output of the following code?

>>> b={1:"A",2:"B",3:"C"}
>>> b.items()

a. dict_items([(1,2,3)])

b. dict_items([(‘A’), (‘B’), (‘C’)])

c. dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

d. Syntax error

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (c) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

Explanation: The method items() returns list of tuples with each tuple having a key-value pair.

[/bg_collapse]

49. What will be the output of this statement?

    z = "xyz"  
    j = "j"  
    while j in z:  
        print(j, end=" ") 

a. x y z

b. xyz

c. j j j j j j j..

d. No output

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]

Answer: (d) No output

Explanation: “j” is not in “xyz”.

[/bg_collapse]

50. What will be the output of the following code?

for i in [1, 2, 3, 4][::-1]:
    print (i)

a. 4 3 2 1

b. 1 2 3 4

c. error

d. none of the mentioned

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: (a) 4 3 2 1[/bg_collapse]

11 comment on “Python Multiple Choice Questions and Answers”

  • admin January 30, 2021
    Reply

    Wow, this article iss nice, my sister is analyzing such things, so I am going to inform
    her.

  • admin February 2, 2021
    Reply

    Hello everyone, it’s my first visit at thiss website, and piece
    of writing is genuinely fruiyful designed for me, keep upp
    posting such articles or reviews.

  • admin February 4, 2021
    Reply

    Hello all, here every person is sharing such know-how, so it’s pleasant to read this website,
    and I used to go to see this website daily.

  • admin February 4, 2021
    Reply

    Excellent post. I waas checking continuously this blog and
    I am impressed! Extremely useful information. I care for such information a lot.

    I was looking for this certain information for
    a very long time.Thank you and gokod luck.

  • admin February 4, 2021
    Reply

    Hello to every one, since I am genuinely keen of
    reading this website’s post to be updated regularly.It
    carries nice data.

  • admin February 4, 2021
    Reply

    Wow, amazing blog layout! How long have you beedn blogging for?
    you made blogging look easy. The overall look of your web site is excellent,
    as well as the content.

  • admin February 4, 2021
    Reply

    Very good post! We willl be linking to this great conternt
    on our website.Keep up the grfeat writing!

  • admin February 4, 2021
    Reply

    Hello! I wieh to say thhat this post is awesome, great
    written and come with approximately all important infos.
    I’d like to ook extra posts like this! 🙂

  • admin February 4, 2021
    Reply

    Very good info. Luciy mme I discovcered your blog by accident.

    I have book-marked it forr later!

  • admin March 8, 2021
    Reply

    Excellent weblog right here! Additionally your web
    site loads up fast! What host are you using? Can I get your affiliate hyperlink to your host?

    I desire my website loaded up as quickly as yours lol

  • admin March 9, 2021
    Reply

    great issues altogether, you just received a emblem new reader.
    What might you suggest about your publish that you just made a few days
    ago? Any sure?

Write a comment