Free Data Science with Python (Basic) Questions and Answers — Questions and Answers
Question 1: When is ___ It ____ function is called, in Python
- If ___init___ is customized by user (Correct answer)
- If < is used (Correct answer)
- If sequence is traversed
- If tuple is used
Correct answer: If ___init___ is customized by user
Python automatically calls __init__ whenever a new instance of a class is created, in order to initialize the object's attributes. It runs on instantiation regardless of whether you defined it yourself or inherited it — traversing a sequence or using a tuple does not trigger it. (Note: the option wording is weak; __init__ fires on every object creation, not only when 'customized'.)
Question 2: Beyond the formal parameter list in Python, the variadic arguments are contained in
- Stack
- Dictionary
- Tree (Correct answer)
- Tuple (Correct answer)
Correct answer: Tree
When a function uses *args, Python packs the extra positional arguments into a TUPLE — an immutable ordered collection. It is not a stack, dictionary, or tree. ⚠ The stored key ('Tree') is wrong, and the correct value 'tuple' is not among the options, so this question should be rewritten.
Question 3: In Python, the pass statement is utilized for
- Jump to loop condition check
- Do nothing
- Jump to loop's else block (Correct answer)
- Jump out of the loop
Correct answer: Jump to loop's else block
The pass statement is a null operation: it does nothing and is used as a placeholder where syntax requires a statement but no action is wanted. It does not jump to a loop's else block, recheck the condition, or break out — those are the jobs of normal flow, continue, and break. ⚠ The correct answer is 'Do nothing'; the stored key is wrong.
Question 4: What does a scikit-learn linear model that estimates sparse coefficients look like?
- Lasso (Correct answer)
- LinearRegression
- None of these
- Ridge Regression
Correct answer: Lasso
Explanation: <br> In scikit-learn, a linear model that estimates sparse coefficients is called Lasso. Lasso stands for "Least Absolute Shrinkage and Selection Operator." It is a linear regression model that performs both regularization and feature selection.
Question 5: When traversing a dictionary in Python, method returns both the key and the value.
- In
- Items (Correct answer)
- Enumerate
- Extend
Correct answer: Items
Explanation: <br> To retrieve both the key and value while traversing a dictionary in Python, you can use the items() method. The items() method returns a view object that contains tuples of key-value pairs from the dictionary.
Question 6: What does the following Python code produce? <br> a, b = 0, 1 <br> while b < 10: <br> print(b, end=' '); a, b = b, a+b
- 1 2 3 5 8
- 1 1 2 3 5
- 1 1 2 3 5 8 1 3 (Correct answer)
- 1 1 2 3 5 8
Correct answer: 1 1 2 3 5 8 1 3
This prints the Fibonacci sequence while b < 10. Tracing b: 1, 1, 2, 3, 5, 8, then b becomes 13 which fails b < 10 and stops — so the output is '1 1 2 3 5 8'. ⚠ The stored key ('1 1 2 3 5 8 1 3') is wrong; the correct output is '1 1 2 3 5 8'.
Question 7: The character used to indicate end of a block in Python, is
- /
- :
- ;
- Nothing (Correct answer)
Correct answer: Nothing
Explanation: <br> In Python, the character used to indicate the end of a block is not a specific character like in some other programming languages. Instead, Python uses indentation to define the blocks of code.
When is ___ It ____ function is called, in Python