WorksheetsIntermediate Python
Total questions: 30
Worksheet time: 15mins
What is the purpose of the try-except block?
Loop control
Exception handling
Function definition
Variable declaration
Which exception is raised when dividing by zero?
ValueError
TypeError
ZeroDivisionError
ArithmeticError
What does the finally clause do?
Executes only if no exception
Executes only if exception occurs
Always executes
Never executes
When does the else clause in try-except execute?
Always
When exception occurs
When no exception occurs
Never
What keyword is used to raise an exception manually?
throw
raise
error
exception
What does if name == "main": check?
Variable name
If module is run directly
Function name
Class name
What is the purpose of the global keyword?
Create global function
Modify global variable
Import global module
Define global class
What does the enumerate() function return?
List of values
List of indices
Index-value pairs
Dictionary
What is list comprehension?
List method
Elegant way to create lists
List sorting
List copying
What will [x*2 for x in range(5)] return?
[0, 1, 2, 3, 4]
[0, 2, 4, 6, 8]
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
What is a virtual environment in Python?
Cloud environment
Isolated Python environment
Testing environment
Virtual machine
Which command creates a virtual environment?
python create env
virtualenv myenv
create virtualenv
env create
What does pip freeze do?
Stops pip
Lists installed packages
Freezes Python version
Clears cache
What is a lambda function?
Named function
Anonymous function
Built-in function
Class method
What will (lambda x: x**2)(5) return?
5
10
25
Error
How many arguments can a lambda function have?
Only one
Only two
Any number
None
What does the join() method do?
Joins two strings
Joins list elements into string
Joins two lists
Joins dictionaries
What will "-".join(["a", "b", "c"]) return?
"a-b-c"
"abc"
["a-b-c"]
Error
What does the format() method do?
Formats numbers
Formats strings with values
Formats dates
Formats files
What will "{0} and {1}".format("A", "B") return?
"0 and 1"
"A and B"
"{A} and {B}"
Error
What does the map() function do?
Creates a map
Applies function to all items
Maps keys to values
Navigates data
What does the filter() function return?
All elements
Elements where function returns True
Filtered dictionary
Sorted list
Where is the reduce() function imported from?
Built-in
functools
itertools
collections
What will list(map(lambda x: x*2, [1, 2, 3])) return?
[1, 2, 3]
[2, 4, 6]
[1, 4, 9]
Error
What does list slicing [::2] mean?
Every element
Every second element
First two elements
Last two elements
What will "Python"[::-1] return?
"Python"
"nohtyP"
"Pytho"
Error
Which of the following is True about tuples?
Mutable
Can be changed
Elements can be added
Immutable
What will {1, 2, 3}.union({3, 4, 5}) return?
{1, 2, 3}
{1, 2, 3, 4, 5}
{3}
Error
What will {1, 2, 3}.intersection({2, 3, 4}) return?
{1, 2, 3, 4}
{2, 3}
{1, 4}
Error
What is the DRY principle in programming?
Don't Repeat Yourself
Do Review Yearly
Define Run Yield
Data Retrieval Yearly
