NEW
Font size
WorksheetsPython
Total questions: 15
Worksheet time: 3mins
What is the purpose of the 'lambda' function in Python?
To create anonymous functions
To create named functions
To create classes
To create modules
What does the 'with' statement in Python ensure?
Proper indentation
Proper error handling
Proper resource management and file closure
Proper variable assignment
Which of the following is a correct way to create a multiline string in Python?
string = """Line 1 \n Line 2"""
string = 'Line 1 \n Line 2'
string = 'Line 1 + Line 2'
string = 'Line 1 \ Line 2'
What is the output of this code?
15
100000
50
100
In Python, what is the purpose of a 'docstring'?
To include a document file in the code
To provide documentation within a function or module
To declare a variable that stores text data
To encrypt code for security
What is the purpose of the 'pass' statement in Python?
To terminate a loop
To raise an exception
To skip a conditional block
To create an empty function or class
What is the output of this code?
1
2
3
4
5
1 3 5
1
3
5
1
2
4
5
In Python, what does the 'zip( )' function do?
Combines two dictionaries
Iterates over two or more lists simultaneously
Compresses a file
Returns the quotient and remainder of division
What will be printed when this code is executed?
8
15
3
5
5
5
What is a decorator in Python?
A design pattern for user interfaces
A module for data visualization
A function that modifies the behavior of another function
A graphical element in a GUI application
How do you open a file named "data.txt" in read mode in Python?
file = open("data.txt", "r")
file = open("data.txt", "read")
file = read_file("data.txt")
file = open("data.txt")
What will be printed when this code is executed?
APPLE
banana
CHERRY
apple
banana
cherry
Apple
Banana
Cherry
APPLE
BANANA
CHERRY
What is the output of this code?
5 4 3 2 1
5
4
3
2
1
1
2
3
4
5
1 2 3 4 5
What will be the output when this code is executed?
1
2
3
4
5
2
4
1 3 5
1
3
5
What will be printed when this code is executed?
0
1
2
3
4
0
2
4
6
8
10
0
2
4
6
8
none
