What is the purpose of the '#' symbol in Python code?
To indicate a code block
To define a variable
To write a comment
To execute a command
What will the following code print?
set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.intersection(set2))
{1, 2, 3, 4, 5}
{3}
{1, 2, 4, 5}
Error
What will the following Python code snippet print?
x = 5 if x > 10: print('A') elif x > 3: print('B') else: print('C')
B
C
The code will result in an error.
A
my_set = {1, 2, 3} my_set.add(3) print(my_set)
{1, 2, 3}
{1, 2, 3, 3}
{3, 1, 2}
What is the value of the expression: '5' + '3'?
'5' + '3'
53
15
8
What is the output of the following Python code snippet?
print(10 / 3)
3.0
3
3.3333333333333335
How can you retrieve the value associated with the key 'name' in a dictionary named 'my_dict'?
my_dict.name
my_dict.get('name')
Both option1 and option3
my_dict['name']
Which assignment operator in Python is used to perform floor division and assign the result?
%=
/=
=
//=
What will the following code snippet print?
x = 5 y = 2 * x print(y)
10
x * 2
2 * x
5
What does the following code accomplish?
sum = 0 for i in range(1, 6): sum += i print(sum)
Prints the numbers from 1 to 5
Calculates the sum of numbers from 1 to 5
Calculates the factorial of 5
Finds the largest number between 1 and 5