Worksheetsclass 12
Total questions: 20
Worksheet time: 10mins
What is the purpose of error handling in Python?
To add new features to the code.
To simplify the code structure.
To improve the speed of the program.
The purpose of error handling in Python is to manage exceptions and ensure program stability.
How do you define a function in Python?
function_name: parameters =>
function_name(parameters) =>
def function_name(parameters):
create function_name(parameters)
What is an identifier in Python? Give an example.
Example of an identifier: my_variable
myVariable123
123_variable
variable-my
Identify the error in the following code: print('Hello World'
Missing closing parenthesis in the print statement.
Missing opening parenthesis in the print statement.
Incorrect function name used in the print statement.
Extra characters after the print statement.
What is the output of the following code: my_list = [1, 2, 3]; print(my_list[1])?
2
4
3
1
How do you concatenate two strings in Python?
Use the '*' operator to concatenate strings.
Use the '+' operator to concatenate strings.
Use the '&' operator to combine strings.
Use the 'concat()' method to join strings.
What is a tuple and how is it different from a list?
A tuple can be changed after creation, whereas a list cannot.
A tuple is a mutable unordered collection of elements, while a list is an immutable ordered collection.
A tuple is an immutable ordered collection of elements, while a list is a mutable ordered collection.
A tuple is a collection of unique elements, while a list can contain duplicates.
What is the syntax to create a list in Python?
list_name : {item1, item2, item3}
list_name = (item1, item2, item3)
list_name =
list_name = [item1, item2, item3]
Explain the concept of a string in Python.
A string in Python is a collection of functions used for data processing.
A string in Python is a sequence of characters enclosed in quotes, which is immutable and can be manipulated using various methods.
A string in Python is a type of number that can be changed after creation.
A string in Python is a variable that can only hold numeric values.
What is the result of the expression (5 > 3) and (2 < 1)?
true
false
1
3
How do you handle exceptions in Python?
Use if-else statements to handle exceptions in Python.
Exceptions cannot be handled in Python.
Use try-except blocks to handle exceptions in Python.
Use switch-case statements to manage exceptions in Python.
What is the difference between a mutable and immutable object in Python?
Mutable objects can be changed; immutable objects cannot be changed after creation.
Mutable objects are faster than immutable objects in all cases.
Mutable objects cannot be changed; immutable objects can be changed after creation.
Both mutable and immutable objects can be changed at any time.
How do you access the last element of a tuple?
Use the index 0 to access the last element of a tuple.
Access the last element by using the length of the tuple.
Use the index -1 to access the last element of a tuple.
You cannot access the last element of a tuple.
What is the purpose of the 'try' and 'except' blocks in Python?
To define functions in Python.
The purpose of 'try' and 'except' blocks in Python is to handle exceptions and errors gracefully.
To import modules in Python.
To create loops in Python.
What will be the output of the following code: my_dict = {'a': 1, 'b': 2}; print(my_dict['b'])?
1
2
'b'
KeyError
How do you create a set in Python?
set_name = [item1, item2, item3]
set_name = {item1, item2, item3}
set_name = (item1, item2, item3)
set_name =
What is the purpose of the 'return' statement in a function?
To end the program.
To return a value from a function to the caller.
To create a loop.
To define a variable.
What is the purpose of the 'with' statement in Python?
To create a new function.
To manage resources efficiently by ensuring proper acquisition and release.
To define a loop structure.
To import modules into the current namespace.
How can you convert a string to an integer in Python?
Use the int() function.
Use the str() function.
Use the float() function.
Use the convert() function.
What is a dictionary in Python?
A collection of key-value pairs that is unordered and mutable.
A sequence of elements that is ordered and immutable.
A type of list that can only contain unique elements.
A collection of functions used for data manipulation.
