How many times will the word 'Hello' be printed?
i = 0 while i < 3: print('Hello') i += 1
4
2
3
Infinitely
Which of the following is NOT a valid way to format a string in Python?
% operator
%
concat() function
concat()
f-strings
format() method
format()
What is the correct way to concatenate two strings, 'Hello' and 'World!', with a space in between?
'Hello' & ' ' & 'World!'
"Hello" + " " + "World!"
'Hello' + 'World!'
'Hello' + ' ' + 'World!'
What will be the output of this code snippet?
i = 0 while i < 5: i += 1 if i == 3: continue print(i)
1 2 3 4 5
1 2 4 5
0 1 2 4 5
1 2 3 4
What will the variable 'x' hold after this code executes?
x = 5 x %= 2
2.5
5
1
Which of the following comparison operators means 'not equal to' in Python?
<>
!=
=
==
What is the correct way to access the third element of a list named 'my_list' in Python?
my_list(2)
my_list.get(3)
my_list[2]
my_list[3]
What is the purpose of the return statement in a Python function?
return
To terminate the execution of the entire program.
To print a value to the console.
To declare a new variable inside the function.
To end the execution of the function and optionally send a value back to the caller.
Which of the following is NOT a valid variable name in Python?
my_variable
variable123
123variable
variable_name
What will the following code print?
set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.intersection(set2))
{1, 2, 3, 4, 5}
{1, 2, 4, 5}
{3}
Error