PGDCA topic test

Python Programming MCQ Test

59 Python Programming multiple-choice questions with answers, from the PGDCA syllabus. Instant score, full answer review, free and no signup.

Advertisement

Each attempt picks 25 questions at random from the 59 in this topic.

40% off

Score 50% or more? Get a certificate at 40% off

Finish any PGDCA test on this site with a score of 50% or above and you can claim a course certificate from Alien Institute of Computer at a 40% discount. Your score appears on the result screen with a WhatsApp button that carries it across for you.

Ask about the certificate
Advertisement

All 59 Python Programming questions with answers

1. Who created the Python programming language?

  • A. Dennis Ritchie
  • B. Guido van Rossum
  • C. Bjarne Stroustrup
  • D. James Gosling

Answer: Guido van Rossum

2. What is the correct file extension for a Python file?

  • A. .pt
  • B. .py
  • C. .pyt
  • D. .python

Answer: .py

3. Is Python a compiled or interpreted language?

  • A. Compiled
  • B. Interpreted
  • C. Assembled
  • D. Linked

Answer: Interpreted

4. How are code blocks defined in Python?

  • A. Curly braces { }
  • B. Indentation
  • C. begin and end keywords
  • D. Parentheses

Answer: Indentation

5. Which symbol begins a single-line comment in Python?

  • A. //
  • B. #
  • C. --
  • D. /*

Answer: #

6. Which function displays output in Python 3?

  • A. echo()
  • B. print()
  • C. write()
  • D. display()

Answer: print()

7. Which function reads input from the user in Python 3?

  • A. scan()
  • B. input()
  • C. read()
  • D. get()

Answer: input()

8. What data type does input() return in Python 3?

  • A. int
  • B. str
  • C. float
  • D. It depends on what is typed

Answer: str

9. Which of these is a mutable data type in Python?

  • A. Tuple
  • B. List
  • C. String
  • D. Frozen set

Answer: List

10. Which of these is an immutable data type in Python?

  • A. List
  • B. Tuple
  • C. Dictionary
  • D. Set

Answer: Tuple

11. Which brackets are used to create a list in Python?

  • A. ( )
  • B. [ ]
  • C. { }
  • D. < >

Answer: [ ]

12. Which brackets are used to create a tuple in Python?

  • A. [ ]
  • B. ( )
  • C. { }
  • D. < >

Answer: ( )

13. Which brackets are used to create a dictionary in Python?

  • A. [ ]
  • B. ( )
  • C. { }
  • D. < >

Answer: { }

14. How is data stored in a Python dictionary?

  • A. As an ordered list
  • B. As key-value pairs
  • C. As a matrix
  • D. As a stack

Answer: As key-value pairs

15. What is the index of the first element of a Python list?

  • A. 1
  • B. 0
  • C. -1
  • D. None

Answer: 0

16. What does the index -1 refer to in a Python list?

  • A. An error
  • B. The last element
  • C. The first element
  • D. An empty slot

Answer: The last element

17. Which method adds an element to the end of a list?

  • A. add()
  • B. append()
  • C. insert()
  • D. push()

Answer: append()

18. Which method removes and returns the last element of a list?

  • A. remove()
  • B. pop()
  • C. delete()
  • D. cut()

Answer: pop()

19. Which function returns the number of items in a list?

  • A. size()
  • B. len()
  • C. count()
  • D. length()

Answer: len()

20. Which function generates a sequence of numbers in Python?

  • A. seq()
  • B. range()
  • C. numbers()
  • D. series()

Answer: range()

21. How many numbers does range(5) produce?

  • A. 4
  • B. 5
  • C. 6
  • D. 0

Answer: 5

22. What is the first value produced by range(5)?

  • A. 1
  • B. 0
  • C. 5
  • D. -1

Answer: 0

23. Which keyword defines a function in Python?

  • A. function
  • B. def
  • C. func
  • D. define

Answer: def

24. Which keyword returns a value from a Python function?

  • A. give
  • B. return
  • C. output
  • D. send

Answer: return

25. Which keyword creates a class in Python?

  • A. struct
  • B. class
  • C. object
  • D. type

Answer: class

26. What is the constructor method in a Python class called?

  • A. __new__
  • B. __init__
  • C. __start__
  • D. constructor

Answer: __init__

27. What is the first parameter of a Python instance method by convention?

  • A. this
  • B. self
  • C. me
  • D. cls

Answer: self

28. Which keyword is used to handle exceptions in Python?

  • A. catch
  • B. except
  • C. handle
  • D. rescue

Answer: except

29. Which block always runs whether or not an exception occurs?

  • A. else
  • B. finally
  • C. except
  • D. end

Answer: finally

Advertisement

30. Which keyword raises an exception manually in Python?

  • A. throw
  • B. raise
  • C. error
  • D. signal

Answer: raise

31. Which keyword imports a module in Python?

  • A. include
  • B. import
  • C. using
  • D. require

Answer: import

32. Which operator performs floor division in Python?

  • A. /
  • B. //
  • C. %
  • D. **

Answer: //

33. Which operator raises a number to a power in Python?

  • A. ^
  • B. **
  • C. //
  • D. %%

Answer: **

34. What is the result of 7 // 2 in Python?

  • A. 3.5
  • B. 3
  • C. 4
  • D. 1

Answer: 3

35. Which keyword tests membership in a sequence?

  • A. has
  • B. in
  • C. contains
  • D. within

Answer: in

36. Which value represents 'nothing' in Python?

  • A. null
  • B. None
  • C. nil
  • D. void

Answer: None

37. Which of these is the correct Boolean literal in Python?

  • A. true
  • B. True
  • C. TRUE
  • D. yes

Answer: True

38. Which keyword creates a placeholder that does nothing?

  • A. skip
  • B. pass
  • C. null
  • D. empty

Answer: pass

39. Which loop iterates over the items of a sequence in Python?

  • A. do-while
  • B. for
  • C. repeat
  • D. loop

Answer: for

40. Which statement exits a loop early in Python?

  • A. exit
  • B. break
  • C. stop
  • D. end

Answer: break

41. Which statement skips to the next loop iteration?

  • A. skip
  • B. continue
  • C. next
  • D. pass

Answer: continue

42. Which function converts a string to an integer?

  • A. str()
  • B. int()
  • C. float()
  • D. num()

Answer: int()

43. Which function converts a number to a string?

  • A. int()
  • B. str()
  • C. chr()
  • D. text()

Answer: str()

44. Which method splits a string into a list?

  • A. cut()
  • B. split()
  • C. divide()
  • D. parts()

Answer: split()

45. Which method joins list items into a string?

  • A. merge()
  • B. join()
  • C. concat()
  • D. add()

Answer: join()

46. Which method converts a string to uppercase?

  • A. toUpper()
  • B. upper()
  • C. capital()
  • D. uppercase()

Answer: upper()

47. Which method removes whitespace from both ends of a string?

  • A. trim()
  • B. strip()
  • C. clean()
  • D. cut()

Answer: strip()

48. What is a lambda in Python?

  • A. A loop type
  • B. A small anonymous function
  • C. A module
  • D. A class method

Answer: A small anonymous function

49. What is a list comprehension used for?

  • A. Reading a list from a file
  • B. Building a list concisely from an expression and a loop
  • C. Sorting a list
  • D. Deleting a list

Answer: Building a list concisely from an expression and a loop

50. Which mode opens a file for writing in Python?

  • A. 'r'
  • B. 'w'
  • C. 'a'
  • D. 'x'

Answer: 'w'

51. Which statement automatically closes a file after use?

  • A. try
  • B. with
  • C. using
  • D. open

Answer: with

52. Which module provides mathematical functions in Python?

  • A. calc
  • B. math
  • C. numeric
  • D. arith

Answer: math

53. Which Python library is most used for data analysis with DataFrames?

  • A. NumPy
  • B. pandas
  • C. Django
  • D. Flask

Answer: pandas

54. Which Python library is used for numerical arrays?

  • A. pandas
  • B. NumPy
  • C. requests
  • D. Tkinter

Answer: NumPy

55. Which Python library is used for building desktop GUIs in the standard library?

  • A. Django
  • B. Tkinter
  • C. Flask
  • D. PyGame

Answer: Tkinter

56. Is Python case-sensitive?

  • A. Yes
  • B. No
  • C. Only for keywords
  • D. Only for functions

Answer: Yes

57. Which function returns the data type of a value?

  • A. typeof()
  • B. type()
  • C. datatype()
  • D. kind()

Answer: type()

58. What does PIP stand for in Python?

  • A. Python Installation Program
  • B. Pip Installs Packages
  • C. Python Internal Parser
  • D. Package Import Protocol

Answer: Pip Installs Packages

59. Which set operation returns elements common to two sets?

  • A. union()
  • B. intersection()
  • C. difference()
  • D. merge()

Answer: intersection()

Frequently asked questions

How many Python Programming questions are in this test?

This page has 59 Python Programming MCQs with answers. Each attempt picks 25 of them at random.

Is the Python Programming test free?

Yes — it is free, needs no signup, and you can retake it as many times as you like.

Can I get a certificate for this test?

Score 50% or more and you can claim a certificate from Alien Institute of Computer at 40% off. The WhatsApp button appears on your result screen.

Advertisement
Advertisement