About Python

Following are some of the multiple choice questions on the Python with answers that will help the students in developing their knowledge.

Python MCQ

1. What is a String?

  • A data type that contains whole numbers. eg: 3, 45, 124
  • Numbers with decimal point. eg: 0.5, 2.45, 56.04
  • Group of characters between quotation marks. eg: "dog"
  • Data type that can only be True or False.

2. Is python case sensitive when dealing with identifiers

  • yes
  • no
  • machine dependent
  • none of the above

3. Which of the following is a python tuple

  • [1, 2, 3]
  • (1, 2, 3)
  • {1, 2, 3}
  • {}

4. Which of the following functions is a built-in function in python

  • seed()
  • sqrt()
  • print()
  • factorial()

5. What will be the output of the following python statement

  • a
  • bc
  • bca
  • abc

6. What is the output of the following python code

  • 0 1 2 0
  • 0 1 2
  • Error
  • none of the above

7. Which function is used to close a file in python

8. Which of the following python code creates an empty class

  • class A: return
  • class A: pass
  • class A:
  • It is not possible to create an

9. Which of the following option is not a core data type in the python language?

  • Dictionary
  • Lists
  • Class
  • none of the above

10. What is used to create an object in python

  • Class
  • constructor
  • User-defined functions
  • In-built functions

11. How to create an empty set in python

  • set()
  • 'set'>
  • Both A & B
  • none of the above

12. What will be the output of the following python code

x = 123 for i in x : print (i)
  • 1 2 3
  • 123
  • Error
  • None of the mentioned

13. What would be the output of the following code snippet?

a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'} for key in a_dict: print(key)
  • 'blue''apple''dog'
  • colorfruitpet
  • blueappledog
  • 'color''fruit''pet'

14. Only one element tensors can be converted to python scalars

  • t.size()
  • t. numpy ()
  • Both A & B
  • none of the above

15. What will the output be from the following code?print(9/3)

  • 3
  • 3.0
  • 9/3
  • SyntaxError

16. What is the type of inf in python

  • Boolean
  • Integer
  • Float
  • Complex

17. What is the value of the expression 100 / 25?

  • 4
  • 4.0
  • "4.0"
  • '4.0'

18. What will be the output of the following python function

  • True
  • False
  • 2
  • -4

19. Which of the following is invalid in python

  • _a = 1
  • __str__ = 1
  • Both A & B
  • none of the above

20. Which of the following are true of Python dictionaries:

  • Dictionaries can be nested to any depth.
  • Dictionaries are accessed by key.
  • All the keys in a dictionary must be of the same type.
  • Dictionaries are mutable.

21. What will be the output of the following python

name = 'coder'
print(name)
  • name
  • coder
  • throw error
  • none of the above

22. What will be the output of the following python code max( what are you )

class father:
    def __init__(self, param):
        self.o1 = param
 
class child(father):
    def __init__(self, param):
        self.o2 = param
 
>>>obj = child(22)
>>>print "%d %d" % (obj.o1, obj.o2)

23. What will be output of the following python code

24. Which is used to create an object in python

25. What will be the value of the following python expression

  • 0
  • 2
  • 4
  • 7

26. Which of the following is true for variable names in python

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

27. _______Is used to create an object in python

  • Class
  • constructor
  • Both A & B
  • none‚Äč

28. Which symbol do we use if we want to add a comment to our code?

  • @
  • #
  • *
  • &

29. Which mathematical operator is used to raise five to the second power in python?

  • /
  • ^
  • **
  • none of the above

30. To insert an the string "strawberries" in the first position of a list we use

  • fruit.append("strawberries, 1")
  • fruit.insert("strawberries",0)
  • fruit.insert(1, "strawberries")
  • fruit.insert(0, "strawberries")

31. The condition for a while loop to continue could include which of the following?

  • While something equals something
  • While something is greater than something
  • While something is True
  • All of these

32. What button do you press to compile (run) your program so that it runs in the shell?

  • F3
  • F5
  • F7
  • F9

33. Which two statements are used to implement iteration?

  • IF and WHILE
  • ELSE and WHILE
  • FOR and WHILE
  • IF and ELSE

34. Which type of loop iterates until instructed otherwise?

  • FOR loop
  • WHILE loop

35. A location in memory used to store data that can be changed.

  • Constant
  • Value
  • Variable
  • Iteration

36. Which of the operators do we use if we want at least one condition to be true?

  • and
  • or
  • else
  • not

37. Python allows you to compare strings, but it is not case sensitive.

  • True
  • False

38. Python uses the same symbols for the assignment operator as for the equality operator.

  • True
  • False

39. Which of the following is not a python built in exception

  • nameerror
  • ioerror
  • assignmenterror
  • valueerror

40. Which of the following function is a built-in function in python language

  • seed()
  • sqrt()
  • factorial()
  • print()

41. What would print (10 + 16) produce?

  • 20
  • 22
  • 24
  • 26

42. Consider this dictionary:d = {'foo': 100, 'bar': 200, 'baz': 300}What is the result of this statement:d['bar':'baz']

  • It raises an exception
  • (200, 300)
  • 200 300
  • [200, 300]

43. Suppose x is defined as follows:x = [ 'a', 'b', { 'foo': 1, 'bar': { 'x' : 10, 'y' : 20, 'z' : 30 }, 'baz': 3 }, 'c', 'd']What is the expression involving x that accesses the value 30?

  • x[2]["bar"]["z"]
  • x[2]["bar"]
  • x["bar"]["z"]
  • x[2]["bar"]["z"][3]

44. Python function names follow the same rules for naming variables.

  • True
  • False

45. Which of these is the correct code for creating a list of names?

  • nameList = John, Harry, Jesse, John, Harry, Harry
  • nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
  • nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
  • nameList = [John, Harry, Jesse, John, Harry, Harry]

46. What will be the output?name = "Dave"print (name)

  • Dave
  • 'Dave'
  • name
  • (name)

47. If you want to create an empty list called colours in Python, which of the following is correct?

  • colours = [ ]
  • colours = ( )
  • colours = { }
  • colours = <>

48. What is the answer of this expression, 22 % 3 is?

  • 7
  • 1
  • 0
  • 5

49. What will the output be from the following code?print("Hello world!\nHello world!")

  • Hello world! Hello world!
  • Hello world!Hello world!
  • SyntaxError
  • Hello world!

50. To solve a problem that requires the user to enter 10 numbers would use what type of iteration?

  • While loop
  • For loop
  • Variable
  • Selection

Enjoyed the Quiz. Share this with friends

Comments

Add Your Review

Your email address will not be published.

Subscribe to Newsletter!

Subscribe to get latest updates and information.