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