Python Multiple Choice Questions and Answers

Python Multiple Choice Questions and Answers

1. Python is a

High-level programming language
Low-level scripting language
Middle-level programming language
High-level scripting language

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

Subtraction and Division
Power and Division
Division and Multiplication
Division, Power, Multiplication, Addition and Subtraction

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

x**y
x ^ ^ y
x ^ * y
x ^ y

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

var
_try_
_var
try

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

with
raise
val
try

6. What will be the output of this statement?

>>>"x"+"yz"

xyz
x yz
x+yz
x

7. Set members must not be hashable.

True
False

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

79 characters
35 characters
22 characters
none of the mentioned

9. Which of the following declarations is incorrect?

_a = 4
__abc__ = 9
__a = 1
None of these

10. All keywords in Python are in

UPPER CASE
lower case
Capitalized
None of the mentioned

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

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

>>> a

Operator not valid for tuples
(‘NeuralBeastNeuralBeastNeuralBeast’)
(‘NeuralBeast’,’NeuralBeast’,’NeuralBeast’)
Syntax error

12. Which of the following cannot be a variable?

in
it
on
__init__

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

print()
val()
num()
None of these

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

Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

15. What will be the output of this function?

round(12.638)

13
12.69
12
127

16. What will be the output of this statement?

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

0xA + 0xB + 0xC
63
33
None of these

17. What will be the output of this code?

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

True
False
Invalid Code
None of these

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

0
-1
1
2

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

dict([[1,”A”],[2,”B”]])
{1,”A”,2”B”}
{1: ‘A’, 2: ‘B’}
{ }

20. Is Python case sensitive when dealing with identifiers?

machine dependent
yes
no
none of the mentioned

21. What will be the output of this function?

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

0
True
False
Invalid code

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

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

a
A
B
Error

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

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

>>> a

frozenset({5,6,7})
{5,6,7}
Error, not possible to convert set into frozenset
Syntax error

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

int
bool
str
Error

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

pow(x,y,z)

(x / y) * z
(x**y) / z
(x / y) / z
(x**y) % z

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

print("D", end = ' ')

print("Z", end = ' ')

print("Y", end = ' ')

print("X", end = ' ')

XYZA
AZYX
A Z Y X
A, Z, Y, X will be displayed on four lines

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

Multiplication, Division and Addition
Multiplication, Division, Addition and Subtraction
Addition and Multiplication
Addition and Subtraction

28. What will be the output of this statement?

d = {0, 1, 2}

for x in d:

   print(x)

0 1 2
{0, 1, 2} {0, 1, 2} {0, 1, 2}
Syntax_Error
None of these above

29. What will be the output of this code?

import math

abs(math.sqrt(36))

6
-6
6.0
Error

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

mylist = list([1, 2, 3])
mylist = []
mylist = list()
all of the mentioned

31. Is the following Python code valid or not?

a={1,2,3}

b={1,2,3,4}

c=a.issuperset(b)

print(c)

True
False
Syntax error for issuperset() method
Error, no method called issuperset() exists

32. What will be the output of this statement?

str1 = "neural"

str2 = ":"

str3 = "beast"

print(str1[-1:])

n
l
neural
beast

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

underscore and ampersand are the only two special characters allowed
all private members must have leading and trailing underscores
unlimited length
none of the mentioned

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

x = 'abcd'

for i in range(len(x)):

   x[i].upper()

print (x)

bcd
ABCD
abcd
None of these

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

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

>>> sum(a,3)

The method sum() doesn’t exist for tuples
Too many arguments for sum() method
9
12

36. Lambda is a statement.

True
False

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

min()
ord()
chr()
any()

38. hat is the method inside the class in python language?

Function
Object
Argument
Attribute

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

>>> a={1,2,3}

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

{8,10}
{8, 2, 10, 4, 6}
{2,4,6}
Error, set comprehensions aren’t allowed

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

>>> b={1:"A",2:"B",3:"C"}

>>> b.items()

dict_items([(1,2,3)])
dict_items([(‘A’), (‘B’), (‘C’)])
dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
Syntax error