0% found this document useful (0 votes)
6 views

python-1

The document contains a series of multiple-choice questions (MCQs) related to Python programming concepts, covering topics such as debugging, programming methodologies, data structures, algorithms, and recursion. Each question is followed by four answer options, with the correct answer indicated. This collection serves as a study guide for individuals preparing for Python-related assessments.

Uploaded by

baliyanarpit291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

python-1

The document contains a series of multiple-choice questions (MCQs) related to Python programming concepts, covering topics such as debugging, programming methodologies, data structures, algorithms, and recursion. Each question is followed by four answer options, with the correct answer indicated. This collection serves as a study guide for individuals preparing for Python-related assessments.

Uploaded by

baliyanarpit291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PYTHON 100 MCQ

1. Which of the following best defines "problem defini on" in program planning?

o A) Debugging code

o B) Iden fying program inputs and outputs

o C) Wri ng pseudocode

o D) Execu ng a program
Answer: B

2. What is the main purpose of debugging?

o A) Designing program layout

o B) Removing logical and syntax errors

o C) Wri ng documenta on

o D) Crea ng a user interface


Answer: B

3. Which type of error is caused by incorrect logic in the program?

o A) Syntax error

o B) Run me error

o C) Logical error

o D) Compila on error
Answer: C

4. Which of the following is not a programming methodology?

o A) Bo om-up

o B) Top-down

o C) Le -right

o D) Structured
Answer: C

5. Which diagram is used for visualizing algorithm flow?

o A) Venn diagram

o B) Pie chart

o C) Flowchart
o D) Decision tree
Answer: C

6. Structured programming includes:

o A) GOTO statements

o B) Sequence, selec on, and itera on

o C) Random instruc ons

o D) Manual opera ons


Answer: B

7. What does documenta on in programming refer to?

o A) File encryp on

o B) Recording program errors

o C) Descrip ve explana on of code

o D) Dele ng temporary files


Answer: C

8. Which of the following is a tool for decision making in problem solving?

o A) Compiler

o B) Decision table

o C) IDE

o D) Debugger
Answer: B

9. Which method starts from a general idea and works toward specifics?

o A) Bo om-up

o B) Top-down

o C) Inside-out

o D) Backward chaining
Answer: B

10. In which concept are small problems solved first and then integrated?

 A) Linear programming

 B) Top-down

 C) Bo om-up

 D) Dynamic programming
Answer: C

11. Which symbol is used to start comments in Python?


 A) //

 B) #

 C) /*

 D) <!--
Answer: B

12. Which of the following is a valid iden fier in Python?

 A) 2data

 B) my-name

 C) _value

 D) class
Answer: C

13. What will be the output of: print(2 + 3 * 5)?

 A) 25

 B) 17

 C) 15

 D) 21
Answer: B

14. Which operator is used for exponen a on in Python?

 A) ^

 B) **

 C) ~

 D) %
Answer: B

15. What is the output of print(True and False)?

 A) True

 B) False

 C) 0

 D) 1
Answer: B

16. The input() func on returns:

 A) Integer

 B) Float

 C) String
 D) Boolean
Answer: C

17. Which statement is used to exit from a loop prematurely?

 A) con nue

 B) exit

 C) stop

 D) break
Answer: D

18. Which keyword is used to define a func on in Python?

 A) func on

 B) func

 C) define

 D) def
Answer: D

19. What is the default return value of a func on that does not explicitly return anything?

 A) null

 B) None

 C) 0

 D) Undefined
Answer: B

20. Which of the following is not a valid control structure in Python?

 A) if

 B) for

 C) do-while

 D) while
Answer: C

21. What is the key feature of a recursive func on?

 A) Calls another func on

 B) Calls itself

 C) Uses loops

 D) Contains a return statement


Answer: B
22. What is a stack diagram used for in recursion?

 A) Show memory usage

 B) Show recursion calls and returns

 C) Op mize loops

 D) Debug syntax errors


Answer: B

23. What will a, b = b, a do in Python?

 A) Swap values of a and b

 B) Assign both to None

 C) Raise an error

 D) Mul ply a and b


Answer: A

24. Which keyword is used to return a value from a func on?

 A) return

 B) yield

 C) output

 D) pass
Answer: A

25. Which loop is best suited for checking a condi on before execu ng?

 A) for

 B) do-while

 C) whileHow do you access the last element of a list named myList?

 A) myList[0]

 B) myList[1]

 C) myList[-1]

 D) myList[len]
Answer: C

32. What does myList.append(5) do?

 A) Replaces all values with 5

 B) Adds 5 at end of list

 C) Removes 5

 D) Sorts the list


Answer: B
33. Which func on is used to delete a list element by index?

 A) delete()

 B) remove()

 C) del

 D) pop()
Answer: C

34. What is cloning a list?

 A) Dele ng a list

 B) Crea ng a copy of the list

 C) Slicing part of a list

 D) Combining two lists


Answer: B

35. Which of the following is a nested list?

 A) [1, 2, 3]

 B) [“a”, “b”]

 C) [[1, 2], [3, 4]]

 D) [5]
Answer: C

36. Which is the correct syntax to define a class?

 A) class MyClass()

 B) class = MyClass:

 C) class MyClass:

 D) class: MyClass()
Answer: C

37. What is the first argument of a method inside a class?

 A) this

 B) class

 C) self

 D) object
Answer: C

38. Which of the following is a built-in standard library module in Python?

 A) Java

 B) collec ons
 C) main

 D) cpp
Answer: B

39. Which func on is called when an object is created from a class?

 A) del

 B) new

 C) init

 D) call
Answer: C

40. How do you create an object of class Car?

 A) obj = new Car()

 B) obj = Car

 C) obj = Car()

 D) obj.Car()
Answer: C

41. Which of the following is a linear data structure?

 A) Tree

 B) Graph

 C) Stack

 D) HashMap
Answer: C

42. A queue follows which principle?

 A) LIFO

 B) FIFO

 C) FILO

 D) LILO
Answer: B

43. Which of these is not a Python data structure?

 A) list

 B) set

 C) stack

 D) string
Answer: D
44. What is the me complexity of linear search in worst case?

 A) O(1)

 B) O(n)

 C) O(log n)

 D) O(n log n)
Answer: B

45. Which sor ng method repeatedly swaps adjacent elements?

 A) Selec on sort

 B) Bubble sort

 C) Inser on sort

 D) Merge sort
Answer: B

46. What is the average me complexity of binary search?

 A) O(n)

 B) O(1)

 C) O(log n)

 D) O(n^2)
Answer: C

47. Which algorithm builds the sorted list one element at a me?

 A) Bubble sort

 B) Merge sort

 C) Inser on sort

 D) Quick sort
Answer: C

48. Which data structure allows fast membership tes ng?

 A) List

 B) Tuple

 C) Set

 D) String
Answer: C

49. The data structure where elements can be added or removed from both ends:

 A) Stack

 B) Queue
 C) Deque

 D) Tree
Answer: C

50. Which of these is used for Last-In-First-Out access?

 A) Queue

 B) Stack

 C) Array

 D) Set
Answer: B

51. Which of the following best describes "structured programming"?

 A) Uses goto statements

 B) Emphasizes breaking down problems into func ons

 C) Depends on global variables

 D) Uses only classes and objects


Answer: B

52. What is the primary goal of top-down programming design?

 A) Op mize machine performance

 B) Break the program into modules from high-level to low-level

 C) Start coding immediately

 D) Avoid documenta on
Answer: B

53. Which diagram is useful in tracing recursive calls and returns?

 A) UML diagram

 B) Flowchart

 C) Stack diagram

 D) Gan chart
Answer: C

54. Which of the following best demonstrates recursion?

 A) A loop with break

 B) A func on calling itself

 C) A func on calling a helper func on

 D) A switch case statement


Answer: B
55. What is the purpose of the ternary operator in Python?

 A) Simplify if-else statements

 B) Mul ply values

 C) Break loops

 D) Call recursive func ons


Answer: A

56. Which of the following is not a valid literal in Python?

 A) 0b101

 B) 3.14

 C) "Hello"

 D) 2e2.5
Answer: D

57. What is the output of: print("5" * 3)?

 A) 15

 B) 555

 C) Error

 D) 5 * 3
Answer: B

58. Which is used to handle excep ons in Python?

 A) try-expect

 B) try-except

 C) catch-except

 D) handle-catch
Answer: B

59. Which statement can be used to skip the rest of the code inside a loop for current itera on?

 A) break

 B) skip

 C) con nue

 D) exit
Answer: C

60. What does the following code output?

def f(): pass

print(f())
 A) None

 B) 0

 C) Error

 D) pass
Answer: A

61. What is the result of list("abc")?

 A) ['abc']

 B) ['a', 'b', 'c']

 C) ['a b c']

 D) abc
Answer: B

62. What is the output of "python".find("t")?

 A) 2

 B) 1

 C) 3

 D) True
Answer: A

63. Which method removes the first matching value in a list?

 A) remove()

 B) pop()

 C) del()

 D) discard()
Answer: A

64. What does list1 + list2 do in Python?

 A) Merges two lists

 B) Adds corresponding elements

 C) Creates tuple

 D) Creates dic onary


Answer: A

65. What does list1 * 2 do?

 A) Doubles values

 B) Mul plies all values

 C) Repeats the list


 D) Error
Answer: C

66. A class method is defined using which decorator?

 A) @sta c

 B) @classmethod

 C) @method

 D) @self
Answer: B

67. Which method is called when an object is destroyed?

 A) delete

 B) destroy

 C) del

 D) finalize
Answer: C

68. What does isinstance(obj, Class) check?

 A) Whether obj is a class

 B) Whether obj is an instance of Class

 C) Whether Class inherits obj

 D) Whether obj is callable


Answer: B

69. What happens when we call sorted(set([3,1,4,1,5]))?

 A) [1, 3, 4, 5]

 B) [3, 1, 4, 5]

 C) [1, 1, 3, 4, 5]

 D) Error
Answer: A

70. What will set([1, 2, 2, 3]) return?

 A) [1, 2, 2, 3]

 B) {1, 2, 2, 3}

 C) {1, 2, 3}

 D) Error
Answer: C

71. Which of the following has O(1) average lookup me?


 A) List

 B) Set

 C) Tuple

 D) String
Answer: B

72. What is the output of:

def fact(n): return 1 if n == 0 else n * fact(n - 1)

print(fact(3))

 A) 6

 B) 9

 C) 3

 D) Error
Answer: A

73. What is a key feature of selec on sort?

 A) Always stable

 B) Minimum swaps

 C) Uses pivot

 D) Divide and conquer


Answer: B

74. Which is faster for searching in large sorted data?

 A) Linear search

 B) Binary search

 C) Bubble search

 D) Tree traversal
Answer: B

75. How many comparisons does linear search do in worst case for n items?

 A) 1

 B) n

 C) n/2

 D) log(n)
Answer: B

76. Which Python module provides array support with fixed types?

 A) array
 B) list

 C) typing

 D) numpy
Answer: A

77. What is the advantage of using recursion?

 A) Less memory

 B) Easier for complex problems like tree traversals

 C) Be er performance always

 D) Avoids base case


Answer: B

78. What does break do in nested loops?

 A) Exits only the inner loop

 B) Exits all loops

 C) Skips current itera on

 D) Restarts loop
Answer: A

79. What is the result of not (True and False)?

 A) True

 B) False

 C) Error

 D) None
Answer: A

80. What will bool("") evaluate to?

 A) True

 B) False

 C) 0

 D) None
Answer: B

81. What is the me complexity of inser ng at the end of a Python list?

 A) O(1)

 B) O(n)

 C) O(log n)
 D) O(n log n)
Answer: A

82. What is the me complexity of removing an element from the middle of a list?

 A) O(1)

 B) O(n)

 C) O(log n)

 D) O(n^2)
Answer: B

83. Which Python structure guarantees uniqueness?

 A) List

 B) Tuple

 C) Set

 D) Array
Answer: C

84. Which func on is used to convert a string into a list of characters?

 A) explode()

 B) char()

 C) list()

 D) strtolist()
Answer: C

85. What is the default mode of the open() func on?

 A) read ('r')

 B) write ('w')

 C) append ('a')

 D) binary ('b')
Answer: A

86. Which is faster: dic onary lookup or list lookup?

 A) Dic onary

 B) List

 C) Same

 D) Depends on size
Answer: A

87. Which sor ng algorithm has the best average me complexity?


 A) Bubble Sort

 B) Merge Sort

 C) Selec on Sort

 D) Inser on Sort
Answer: B

88. Which method adds an element at a specific index in a list?

 A) insert()

 B) append()

 C) push()

 D) add()
Answer: A

89. What will be the result of bool([])?

 A) True

 B) False

 C) None

 D) 0
Answer: B

90. Which Python keyword is used to define a class?

 A) object

 B) def

 C) struct

 D) class
Answer: D

91. Which built-in func on returns the memory address of an object?

 A) mem()

 B) id()

 C) ref()

 D) address()
Answer: B

92. What is printed by: print(type([]) is list)?

 A) True

 B) False

 C) list
 D) Error
Answer: A

93. Which loop is most appropriate when the number of itera ons is unknown?

 A) for

 B) while

 C) do-while

 D) repeat
Answer: B

94. Which of the following does not support item assignment?

 A) List

 B) Dic onary

 C) Tuple

 D) Set
Answer: C

95. What does the pass statement do?

 A) Skips func on

 B) Placeholder for future code

 C) Exits loop

 D) Repeats loop
Answer: B

96. What does the in keyword test?

 A) Membership

 B) Index

 C) Type

 D) Range
Answer: A

97. How is excep on handling done in Python?

 A) if-else

 B) try-catch

 C) try-except

 D) switch-case
Answer: C

98. What is a decorator in Python?


 A) A comment

 B) A wrapper to modify func ons

 C) A method in a class

 D) A type of loop
Answer: B

99. How are arguments passed in Python func ons?

 A) Pass by value

 B) Pass by reference

 C) Pass by object-reference

 D) Pass by copy
Answer: C

100. What does PEP stand for in Python?

 A) Python Enhancement Proposal

 B) Python Execu on Protocol

 C) Programming Efficient Python

 D) Python En ty Processor
Answer: A

You might also like