Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Python MCQ

01. Who developed Python Programming Language?


a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
Ans: c

2. Is Python code compiled or interpreted?


a) Python code is both compiled and interpreted
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpreted
Ans: b

3. What will be the value of the following Python expression?


4+3%5
a) 7
b) 2
c) 4
d) 1
Ans: a

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

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

i+=1
a) 1 2 3
b) error
c) 1 2
d) none of the mentioned
Ans: b

5. Which of the following is the truncation division operator in Python?


a) |
b) //
c) /
d) %
Ans : b

6. Which of the following is not a core data type in Python programming?


a) Tuples
b) Lists
c) Class
d) Dictionary
Ans : c

7. What is the order of namespaces in which Python looks for an identifier?


a) Python first searches the built-in namespace, then the global namespace and finally the
local namespace
b) Python first searches the built-in namespace, then the local namespace and finally the
global namespace
c) Python first searches the local namespace, then the global namespace and finally the built-
in namespace
d) Python first searches the global namespace, then the local namespace and finally the built-
in namespace
Ans: c

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


a) pass
b) eval
c) assert
d) nonlocal
Ans: b

9. What arithmetic operators cannot be used with strings in Python?


a) *
b) –
c) +
d) All of the mentioned
Ans: b

10. To add a new element to a list we use which Python command?


a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
Ans: c

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


a) 79 characters
b) 31 characters
c) 63 characters
d) none of the mentioned
Ans :d
12. Which of the following is a feature of Python DocString?
a) In Python all functions should have a docstring
b) Docstrings can be accessed by the __doc__ attribute on objects
c) It provides a convenient way of associating documentation with Python modules,
functions, classes, and methods
d) All of the mentioned
Ans: d

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

a)16
b) 32
c) 64
d) None of the above
Ans : d

14. In which year was the Python 3.0 version developed?


a) 2008
b) 2000
c) 2010
d) 2005
Ans : a

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

a) Object
b) Function
c) Attribute
d)Argument
Ans: b

16. Which one of the following has the highest precedence in the expression?
a) Division
b) Subtraction
c) Power
d) Parenthesis
Ans :d

17. What will be the output after the following statements?


x=5
y=4
print(x % y)
a) 0
b) 20
c) 1.0
d)1
Ans : 1

18. What is the data type of x after the following statement?


x = [‘Today’, ‘Tomorrow’, ‘Yesterday’]
a. List
b. Dictionary
c. Tuple
d. String
Ans : a

19. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on
Ans : b

20. A function in Python begins with which keyword?


a) void
b) return
c) def
d) int
Ans: c

21. Which of the following declarations is incorrect?


a) _x = 2
b) ____x = 3
c) __xyz__ = 5
d) None of these

Ans: d

22. Which of the following statements assigns the value 25 to the variable x in Python:
a) x ← 25
b) x = 25
c) x := 25
d) int x = 25
Ans :c
23. Select the correct example of complex datatype in Python
a) 3 + 2j
b) -100j
c) 5j
d) All of the above are correct
Ans :d
24. If x=3.123, then int(x) will give?
a) 1
b) 0
c) 1
d) 3
Ans:d

25. Identify tuple from the following-


a) [3]
b) {1, 2, 3}
c) (1, 2, 3, 4)
d) None of the Above
Ans :c

26. Which of the following is/are correct ways of creating strings ?


a) name = Jiya
b) name = ‘Jiya’
c) name = “Jiya
d) name = (Jiya)
Ans : b

27. Escape sequences are treated as ………. .


a) strings
b) characters
c) integers
d) none of these
Ans : b

28. Which of the following is an escape sequence for a newline character ?


a) \a
b) \t
c) \n
d) \b
Ans: c

29. Which of the following functions print the output to the console ?
a) Output( )
b) Print( )
c) Echo( )
d) print( )
Ans : d

30. The input ( ) returns the value as ………. type.


a) integer
b) string
c) floating point
d) none of these
Ans: b

31. To print a line a text without ending it with a newline… argument is used with print ( )
a) sep
b) newline
c) end
d) next
Ans: c

32. Python is____


a) High-Level
b) Interpreted
c) Object-Oriented
d) All of the Above
Ans :d

33. Which of the following keywords is not reversed keyword in python?


a) None
b) class
c) goto
d) and
Ans: c

34. Name the statement that sends back a value from a function.
a) print
b) return
c) input
d) none
Ans: b
35. Which values are used by the functions to communicate information back to the caller?
a) local
b) global
c) random
d) return
Ans :d
36. Which line of code produces an error?
a) “PythonMcq” + “12”
b) ‘PythonMcq’ + 16
c) 3 + 7
d) ‘PythonMcq’ + “21”
Ans: b

37. How many keywords present in the python programming language?


a) 32
b) 61
c) 33
d) 27
Ans: c
38. Functions that do not return any value are known as
a) fruitful functions
b) void functions
c) library functions
d) user-defined functions
Ans : b

39. The default separator character of print( ) is ……….


a) tab
b) space
c) newline
d) dot
Ans: b

40. Which of the following are valid identifiers?


a) my name
b) _myname
c) 2myname
d) my-name
Ans: b

You might also like