Practice Library
All MCQs
Browse exam-wise, subject-wise, and country-wise MCQs with explanations.
Medium
Choose an option to check your answer.
A.
Local scope
B.
Probability density
C.
Vectorization
D.
Inheritance
Show Answer
Correct Answer: A. Local scope
Explanation:
Names assigned inside a function are usually local to that function’s execution context. This separation prevents unintended interference with names elsewhere in the program.
Medium
Choose an option to check your answer.
A.
An exception
B.
A parameter
C.
A module
D.
An argument passed during a specific call
Show Answer
Correct Answer: B. A parameter
Explanation:
A parameter is the name listed in a function definition to receive input. An argument is the actual object supplied when the function is called.
Easy
Choose an option to check your answer.
A.
It sends a result back to the caller and ends that function call
B.
It prints every local variable
C.
It restarts the entire program
D.
It imports the function into another module
Show Answer
Correct Answer: A. It sends a result back to the caller and ends that function call
Explanation:
`return` provides the function’s output to the code that called it. Execution of that function call stops when the return statement is reached.
Easy
Choose an option to check your answer.
A.
To display a chart automatically
B.
To define a reusable function
C.
To declare a database table
D.
To delete all variables
Show Answer
Correct Answer: B. To define a reusable function
Explanation:
The `def` statement creates a named block of reusable code. Functions help organize logic and reduce repeated code.
Medium
Choose an option to check your answer.
A.
Define a dictionary key
B.
Repeat an operation until a convergence condition becomes false
C.
Store a fixed pair of coordinates
D.
Import a plotting library
Show Answer
Correct Answer: B. Repeat an operation until a convergence condition becomes false
Explanation:
A `while` loop continues as long as its condition remains true. It is useful when the number of iterations is not known in advance.
Easy
Choose an option to check your answer.
A.
`for` loop
B.
Class definition
C.
Dictionary literal
D.
`try` block
Show Answer
Correct Answer: A. `for` loop
Explanation:
A `for` loop iterates directly over each element of a sequence or iterable. It is clearer than manually managing an index for this task.
Easy
Choose an option to check your answer.
A.
`import`
B.
`return`
C.
`def`
D.
`if`
Show Answer
Correct Answer: D. `if`
Explanation:
An `if` statement controls whether a block runs based on a Boolean condition. It is the basic construct for conditional decision making.
Easy
Choose an option to check your answer.
A.
The middle element
B.
The last element
C.
The first element
D.
No element because negative indices are forbidden
Show Answer
Correct Answer: B. The last element
Explanation:
Negative indexing counts backward from the end of a sequence. Index -1 therefore refers to the final element.
Medium
Choose an option to check your answer.
A.
`[4, 6, 8, 10]`
B.
`[4, 6, 8]`
C.
`[2, 4, 6, 8]`
D.
`[6, 8, 10]`
Show Answer
Correct Answer: B. `[4, 6, 8]`
Explanation:
A slice includes the start index but excludes the stop index. Indices 1, 2, and 3 contain 4, 6, and 8.
Easy
Choose an option to check your answer.
A.
20
B.
An error because indexing starts at 1
C.
30
D.
40
Show Answer
Correct Answer: C. 30
Explanation:
Python uses zero-based indexing, so index 2 refers to the third element. The third value in the list is 30.
Easy
Choose an option to check your answer.
A.
String
B.
Integer
C.
Set
D.
Tuple
Show Answer
Correct Answer: C. Set
Explanation:
Sets retain unique elements and automatically eliminate duplicates. They are therefore useful for identifying distinct category values.
Easy
Choose an option to check your answer.
A.
String
B.
Dictionary
C.
Set only
D.
Tuple
Show Answer
Correct Answer: B. Dictionary
Explanation:
A dictionary maps each unique key to an associated value. This allows direct lookup by meaningful labels such as student IDs or feature names.