Font size
WorksheetsPython Final Assessment
Total questions: 51
Worksheet time: 45mins
Which of the following is a valid variable name in Python?
1variable
variable-name
variable_name
variable name
What will be the output of `print(5 + 3 * 2)` in Python?
16
11
13
23
Which data type is used to store a sequence of characters in Python?
int
list
str
float
How do you take user input in Python?
input()
scan()
read()
get()
What will be the result of `3 ** 2` in Python?
6
9
5
8
How do you denote a comment in Python?
/* comment */
# comment
// comment
Which operator is used to check equality in Python?
=
==
!=
>
What is the output of `print("Hello".format("World"))`?
HelloWorld
Hello World
World
Hello
Which keyword is used to start a conditional statement in Python?
switch
if
when
case
How do you create a list in Python?
[]
{}
()
<>
What will be the output of `print([1, 2, 3] + [4, 5])`?
[1, 2, 3, 4, 5]
[1, 2, 3, [4, 5]]
[1, 2, 3, 4, 5, 4, 5]
[4, 5, 1, 2, 3]
What method adds an element to the end of a list?
append()
add()
insert()
extend()
How do you define a function in Python?
function myFunc()
def myFunc()
func myFunc()
define myFunc()
Which of the following is used to return a value from a function?
return
yield
result
output
What is the output of `print(len("Python"))`?
5
6
7
8
Which Python keyword is used to create a class?
class
create
def
object
What is inheritance in Python?
Creating new classes from existing ones
A method within a class
A way to handle exceptions
A type of loop
How do you open a file for reading in Python?
open("file.txt", "r")
open("file.txt", "write")
open("file.txt", "read")
open("file.txt", "append")
How do you read the entire content of a file in Python?
file.read()
file.readlines()
file.get()
file.scan()
Which module would you use for numerical operations in Python?
scipy
numpy
matplotlib
sympy
How do you import a module in Python?
include module_name
import module_name
use module_name
require module_name
Which method is used to find the length of a list?
length()
size()
count()
len()
What will be the output of the following code? `print("5" * 2)`
10
"55"
52
55
What is the purpose of the `self` keyword in Python classes?
To refer to the instance of the class
To refer to a global variable
To refer to a static method
To create a new instance
How can you check if a number is even in Python?
num % 2 == 0
num % 2 != 0
num // 2 == 0
num & 1 == 0
What will be the output of `print(type(5.0))`?
int
str
float
list
How do you handle exceptions in Python?
try...except
catch...finally
handle...error
error...catch
What is a tuple in Python?
A mutable sequence
An immutable sequence
A dynamic array
A dictionary
Which method is used to remove an item from a dictionary?
remove()
pop()
delete()
discard()
How do you define a class method in Python?
def method_name(self):
@classmethod
def method_name(cls):
@method
What is the result of `print("Python"[:3])`?
Python
Pyt
hon
Which loop is used when the number of iterations is known?
while
for
repeat
do-while
How do you convert a string to an integer in Python?
int()
str()
float()
convert()
What is the default return value of a function that does not have a return statement?
None
0
False
""
Which operator is used for floor division in Python?
/
//
%
**
What is the purpose of the `__init__` method in Python classes?
To initialize class variables
To initialize instance variables
To destroy instance variables
To initialize the class
What will be the output of the following code?
x = [1, 2, 3]
x.append([4, 5])
print(x)
[1, 2, 3, 4, 5]
[1, 2, 3, [4, 5]]
1, 2, 3, 4, 5, 4, 5]
[4, 5, 1, 2, 3]
How do you define a default argument in a function?
def func(arg=default_value):
def func(arg, default_value):
def func(arg, default_value=default_value):
def func(default_value=default_value):
Which method is used to sort a list in ascending order?
sort()
order()
arrange()
arrange_ascending()
What will be the output of the following code?
Which of the following statements is true about Python functions?
Functions can only return one value.
Functions can return multiple values.
Functions cannot return any value.
Functions are only used for mathematical calculations.
What will be the output of the following code?
(a)
What will be the output of the following code?
(a)
You need to handle user input and perform different actions based on the input. You want to execute a specific block of code depending on whether the user enters "start", "stop", or "exit". How should you implement this in Python?
Use a series of if-elif-else statements to check the user input.
Use nested if statements for each condition.
Use a single if statement with multiple conditions connected by or.
Use a switch statement to handle different cases.
You need to merge two dictionaries in Python. Which method would you use if you are using Python 3.9 or later?
dict.update()
dict.merge()
{**dict1, **dict2}
dict.combine()
You want to handle multiple exceptions in a single try block. How should you do this?
Use multiple try blocks for each exception.
Use a single except block with multiple exception types separated by commas.
Use a single except block for each exception type.
Handle each exception using a separate finally block.
You have a list of integers and you want to get the maximum value from it. The function you would use is (a) .
Scenario: To open a file for writing in Python, you should use the mode (a) .
Scenario: To remove leading and trailing whitespace from a string, you use the (a) method.
What will be the output of the following code?
6
5
UnboundLocalError: local variable 'x' referenced before assignment
None
Write a Python function called unique_characters that takes a string as input and returns True if all characters in the string are unique (i.e., no character appears more than once), and False otherwise.
requirements:
The function should be case-sensitive (e.g., 'A' and 'a' are considered different characters).
You cannot use any built-in Python collections like sets or dictionaries for this problem.
Example:
print(unique_characters("hello")) # Output: False
print(unique_characters("world")) # Output: True
print(unique_characters("Python")) # Output: True
print(unique_characters("aAbBcC")) # Output: False
