WorksheetsPython Study Topics Quiz
Total questions: 25
Worksheet time: 13mins
Which of the following is NOT a data type in Python?
Strings
Booleans
Characters
Floats
What operator is used for comparison in Python?
==
!
||
&&
Which string method converts a string to lowercase?
.upper()
.title()
.lower()
.capitalize()
What keyword is used to define a function in Python?
func
def
define
function
Which of the following is a valid way to create a list in Python?
list = [1, 2, 3]
list = <1, 2, 3>
list = {1, 2, 3}
list = (1, 2, 3)
What does the 'yield' keyword do in Python?
Creates a generator
Raises an exception
Returns a value from a function
Ends a loop
Which of the following is an immutable data structure in Python?
Set
Dictionary
Tuple
List
What is the purpose of the 'global' keyword?
To define a global variable
To declare a constant
To import modules
To create a function
Which of the following is a valid way to import a module in Python?
require math
using math
include math
import math
What is a closure in Python?
An error handling mechanism
A data structure
A type of loop
A function that returns another function
Which of the following is NOT a control flow statement?
if
for
while
define
What does the 'append()' method do in a list?
Reverses the list
Sorts the list
Adds an item to the end
Removes an item
Which of the following is a valid way to define a lambda function?
def lambda x: x + 1
lambda x: x + 1
lambda: x + 1
function lambda(x): x + 1
What is the output of the expression '5 // 2' in Python?
3
2.5
2
5
Which of the following is a valid dictionary in Python?
{'one': 1, 'two': 2}
(1, 2, 3)
[1: 'one', 2: 'two']
{1, 2, 3}
What is the purpose of the 'with' statement in file handling?
To write to a file
To read a file
To ensure proper resource management
To open a file
Which of the following is a valid way to create a set in Python?
set = <1, 2, 3>
set = {1, 2, 3}
set = (1, 2, 3)
set = [1, 2, 3]
What does the 'break' statement do in a loop?
Ends the loop
Continues to the next iteration
Exits the program
Pauses the loop
Which of the following is a valid way to define a function with default arguments?
def func(x=1):
func(x=1):
def func(x): x=1
function func(x=1):
What is the output of the expression 'len([1, 2, 3])'?
3
2
1
None
Which of the following is a valid way to slice a list?
list[1, 3]
list{1:3}
list[1:3]
list(1:3)
What is the purpose of decorators in Python?
To modify function behavior
To create classes
To handle exceptions
To define variables
Which of the following is a valid way to read a file in Python?
file.read()
file.get()
file.open()
file.load()
What is the output of the expression '3 * 2 ** 2'?
12
6
8
9
Which of the following is a valid way to create a tuple?
<1, 2, 3>
(1, 2, 3)
{1, 2, 3}
[1, 2, 3]
