Skip to content

MCQ

1. Which value is a bool?

A. 42 B. "42" C. True D. [True]

2. Which collection keeps items unique?

A. list B. tuple C. set D. str

3. What does map do?

A. Sorts items B. Applies a function to each item C. Removes duplicates D. Creates a dictionary

4. Which keyword creates a small anonymous function?

A. def B. lambda C. class D. yield

5. What does indentation define in Python?

A. Variable names B. Blocks of code C. Types D. Imports

6. What does yield usually create?

A. A generator B. A class C. A tuple D. A dictionary

7. What is a closure?

A. A loop B. A function that remembers outer values C. A type hint D. A list comprehension

8. What is Python by default?

A. Statically typed B. Dynamically typed C. Strongly compiled only D. Untyped

9. What does @dataclass help with?

A. Networking B. Simple data classes C. Lazy loading only D. File I/O

10. Which is a concrete type?

A. T B. Any C. int D. TypeVar

11. What is the base case in recursion?

A. The repeated step B. The stop condition C. The import line D. The type hint

12. What does operational semantics describe?

A. How code is styled B. How code runs step by step C. How packages install D. How variables are named

Answers

1-C, 2-C, 3-B, 4-B, 5-B, 6-A, 7-B, 8-B, 9-B, 10-C, 11-B, 12-B

Extended practice: Questions 13–70

Choose one answer. Trace code on paper before checking the key.

No.QuestionABCD
13Which built-in type is immutable?listdictsettuple
14What is len({1, 1, 2})?123Error
15Which expression creates an empty set?{}set()[]()
16A dictionary primarily stores:Unique values onlyKey–value pairsOrdered numbers onlyFunctions only
17What does xs[-1] select?First itemLast itemAll except lastError always
18Which operation mutates list xs?xs + [4]tuple(xs)xs.append(4)xs[0]
19A higher-order function must:Use a loopTake or return a functionBe recursiveReturn a list
20filter(f, xs) retains items for which f returns:A numberA stringTruthyNone
21list(map(lambda x: x*2, [1,2])) equals:[1,2][2,4][2,2]A function
22Which function combines a sequence into one accumulated result?filtermapreducerange
23A pure function normally:Changes global stateHas no observable side effectsReads user inputMutates its argument
24In if/elif/else, how many branches execute in one pass?All true branchesAt most oneExactly twoNone always
25When the number of repetitions is known, which is usually clearest?forInfinite whileRecursion onlymatch only
26What stops a while loop?Its condition becomes falseIt reaches ten iterationsIndentation endsA list is created
27A list comprehension produces:A generator alwaysA listA set alwaysA class
28break does what?Skips one iterationExits the nearest loopRestarts the loopExits Python
29continue does what?Ends the functionExits the loopSkips to the next iterationPauses execution
30A generator is lazy because it:Computes every value immediatelyProduces values on demandCannot be iteratedStores only strings
31Calling a generator function returns:The final yielded valueA generator objectA listNone always
32In a generator, yield normally:Ends the processSuspends state and emits a valueDeletes local variablesImports a module
33Compared with a list of one million items, a generator usually uses:More memoryLess memoryExactly equal memoryNo CPU
34A Python lambda may contain:Multiple statementsOne expressionA class definitionA while statement
35In (lambda x: x + 1)(4), 4 is:An abstractionAn argument in an applicationA return typeA free function
36Lambda abstraction means:Naming a fileDefining a function of a variableCalling a functionDeleting a binding
37A first-class function can be:Passed as an argumentUsed only after classStored only globallyReturned but not stored
38A closure captures variables from its:DatabaseEnclosing lexical scopeImport cacheType checker only
39A function factory usually returns:A newly configured functionA loopA moduleA syntax error
40If f = g, then f refers to:The result of calling gThe function object gA string gNothing
41Dynamic typing associates types primarily with:Variable names foreverRuntime valuesSource filesIndentation levels
42Python is strongly typed because it generally:Silently combines incompatible typesRejects invalid cross-type operationsRequires declarationsCompiles no code
43Type hints are normally:Enforced by the interpreter at every assignmentMetadata for tools and readersA replacement for testsRequired syntax
44isinstance(x, int) checks:A static hintRuntime type membershipVariable scopeMutability
45Type inference means a tool:Guesses randomlyDeduces a type from contextConverts every valueRemoves annotations
46Any tells a static checker to:Reject all operationsPermit essentially any type operationRequire an integerInfer None
47TypeVar('T') is useful for expressing:A fixed integerA relationship among generic typesRuntime castingFile types only
48If a function returns the same type it receives, the best generic signature uses:Unrelated Any valuesThe same TypeVar for input and outputOnly objectNo return type
49A user-defined type is commonly created with:classyieldimportbreak
50@dataclass commonly generates:Network handlersMethods such as __init__ and __repr__A databaseA generator
51An Enum is best for:Arbitrary changing stringsA fixed set of named choicesMutable sequencesAnonymous functions
52An instance is:A class definitionA concrete object created from a classA moduleA protocol only
53Which is a concrete type?list[int]list[T] with unresolved TTypeVar('T')Any as a relationship
54“Concrete” most directly means:Abstract behavior onlyFully specified typeDynamically allocatedImmutable
55Every correct recursive function needs:A classA reachable base caseA global variableA generator
56Recursive calls are tracked using the:Heap onlyCall stackImport pathType table
57Tail recursion in standard Python:Is always optimized awayIs not generally tail-call optimizedCannot terminateRequires yield
58Structural recursion reduces a problem according to:Its data structureClock timeFile size onlyType hints only
59factorial(0) is normally:01Undefined−1
60Operational semantics describes:Valid spelling onlyHow program states change during executionNaming conventionsDocumentation style
61Syntax answers:“What does it do?”“Is it grammatically well formed?”“How fast is it?”“Who wrote it?”
62A small-step semantics models execution as:One final leap onlyA sequence of individual transitionsA type declarationA UML diagram
63A stack frame commonly stores:Local variables and return informationAll disk filesSource-control historyOnly global constants
64Duck typing focuses on an object's:Declared ancestry onlySupported behaviorMemory addressFile name
65A Protocol describes:Required operations/structureA concrete constructor onlyA loop invariantA network only
66An abstract base class may:Define required abstract methodsBe only a stringDisable inheritanceReplace every protocol
67Polymorphism lets:One interface work with multiple typesOne variable have no valueEvery class use identical dataCode avoid functions
68Parametric polymorphism is represented by:Generics/type parametersOnly inheritanceGlobal variablesException handling
69Subtype polymorphism commonly relies on:Compatible derived objectsList slicingLazy iterationArithmetic precedence
70The safest way to answer a code-tracing MCQ is to:Guess from keywordsTrack values and control flow step by stepChoose the longest optionIgnore types

Extended answer key

13-D, 14-B, 15-B, 16-B, 17-B, 18-C, 19-B, 20-C, 21-B, 22-C, 23-B, 24-B, 25-A, 26-A, 27-B, 28-B, 29-C, 30-B, 31-B, 32-B, 33-B, 34-B, 35-B, 36-B, 37-A, 38-B, 39-A, 40-B, 41-B, 42-B, 43-B, 44-B, 45-B, 46-B, 47-B, 48-B, 49-A, 50-B, 51-B, 52-B, 53-A, 54-B, 55-B, 56-B, 57-B, 58-A, 59-B, 60-B, 61-B, 62-B, 63-A, 64-B, 65-A, 66-A, 67-A, 68-A, 69-A, 70-B.

Built from Markdown with VitePress.