WorksheetsBeginner Python Programming Assessment
Total questions: 30
Worksheet time: 15mins
What is the correct syntax to output 'Hello, World!' in Python?
print('Hello, World!')
print('Hello World!')
echo 'Hello, World!'
println('Hello, World!')
Which of the following is a valid variable name in Python?
valid_variable_name
variable-name
invalidVariableName!
123variableName
What is the purpose of the 'def' keyword in Python?
The 'def' keyword is used to import modules in Python.
The 'def' keyword is used to create a class in Python.
The 'def' keyword is used to declare a variable in Python.
The 'def' keyword is used to define a function in Python.
How do you create a list in Python?
You create a list in Python using curly braces, e.g., my_list = {item1, item2, item3}.
You create a list in Python using angle brackets, e.g., my_list =
You create a list in Python using square brackets, e.g., my_list = [item1, item2, item3].
You create a list in Python using parentheses, e.g., my_list = (item1, item2, item3).
What will be the output of the following code: print(type(5))?
5
int
<class 'int'>
None
What is the difference between a local variable and a global variable?
Local variables persist for the entire program, whereas global variables are temporary.
Local variables are scoped to their function, while global variables are accessible throughout the program.
Local variables can be accessed globally, while global variables are limited to their function.
Local variables are defined outside functions, while global variables are defined inside functions.
How do you define a function that takes two parameters in Python?
my_function(param1; param2)
def my_function(param1, param2, param3):
def my_function(param1, param2):
function my_function(param1, param2)
Which library would you use to perform mathematical operations in Python?
numpy
pandas
math
scipy
What is the correct way to handle exceptions in Python?
Implement error handling with switch cases.
Use if-else statements to manage errors.
Use try-except blocks to handle exceptions.
Ignore exceptions and let the program crash.
What data structure would you use to store key-value pairs in Python?
dictionary
tuple
list
set
How do you concatenate two strings in Python?
Use the '+' operator to concatenate strings.
Use the '*' operator to join strings.
Apply the 'concat()' method for strings.
Utilize the '&' operator for string merging.
What is the output of the expression: 3 * 'Python'?
3 * Python
PythonPythonPython
Python3Python
PythonPython3
How can you import the 'math' library in Python?
require math
import mathlib
import math
include math
What is the purpose of the 'return' statement in a function?
The 'return' statement is used to define a function's parameters.
The 'return' statement ends the execution of a program entirely.
The 'return' statement is for printing output to the console.
The purpose of the 'return' statement is to provide a value from a function to its caller.
Which of the following is a mutable data type in Python?
tuple
list
set
frozenset
How do you access the first element of a list named 'my_list'?
my_list[0]
my_list.first()
my_list.get(0)
my_list(1)
What will happen if you try to access a variable that has not been defined?
The variable is initialized to zero.
The program will terminate.
A reference error is raised.
A syntax error is raised.
How do you create a dictionary in Python?
A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').
You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.
You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].
To create a dictionary in Python, use a list, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].
What is the output of the following code: print(10 / 2)?
10 / 2
5.0
10
5
How can you check the length of a list in Python?
size(my_list)
count(my_list)
length(my_list)
len(my_list)
What method would you use to remove an item from a list in Python?
my_list.pop(item)
my_list.erase(item)
delete(my_list, item)
my_list.remove(item)
How can you check if a key exists in a dictionary in Python?
key in my_dict
my_dict.has_key(key)
key.exists(my_dict)
my_dict.contains(key)
What is the output of the following code: print('Hello' + ' ' + 'World!')?
HelloWorld!
Hello + World!
None
Hello World!
What is the correct way to create a set in Python?
my_set = [1, 2, 3]
my_set = {1, 2, 3}
my_set = (1, 2, 3)
my_set = <1, 2, 3>
How do you convert a string to an integer in Python?
int('123')
str(123)
convert('123')
integer('123')
What is the output of the following code: print(2 ** 3)?
2
9
6
8
How do you create a tuple in Python?
You create a tuple using square brackets, e.g., my_tuple = [item1, item2].
You create a tuple using parentheses, e.g., my_tuple = (item1, item2).
You create a tuple using curly braces, e.g., my_tuple = {item1, item2}.
You create a tuple using angle brackets, e.g., my_tuple =
How do you add an item to the end of a list in Python?
my_list.add(item)
my_list.push(item)
my_list.insert(item)
my_list.append(item)
What is the correct way to define a class in Python?
MyClass class:
define MyClass:
class MyClass:
class: MyClass
How do you remove the last item from a list in Python?
my_list.delete()
my_list.pop()
my_list.remove_last()
my_list.erase()
