Which method is used to convert a string to uppercase in Python?
uppercase()
toUpperCase()
upper()
toUpper()
What is the correct way to access the third element of a list named 'my_list' in Python?
my_list[3]
my_list[2]
my_list(2)
my_list.get(3)
What happens if a function doesn't explicitly use the 'return' keyword?
The function will return 'None'.
The function will raise a SyntaxError.
The function will enter an infinite loop.
The function will return a random value.
What is the correct way to print 'Hello, World!' in Python?
print('Hello, World!')
System.out.println('Hello, World!')
console.log('Hello, World!')
echo 'Hello, World!'
What is the primary purpose of using functions in Python?
To define data structures like lists and dictionaries.
To reduce the memory consumption of the program.
To increase the execution speed of the program.
To make the code more readable and organized.
How many times will the word 'Hello' be printed?
for i in range(3): print('Hello')
2
3
0
1
What will the following code print?
my_set = {1, 2, 3} my_set.add(3) print(my_set)
Error
{1, 2, 3, 3}
{3, 1, 2}
{1, 2, 3}
Which assignment operator in Python is used to perform floor division and assign the result?
/=
//=
%=
=
Which statement is true about the else block in a while loop?
else
while
It executes only if the loop condition becomes false.
The else keyword cannot be used with a while loop.
It always executes after the loop finishes.
It executes only if the loop contains a break statement.
break
How can you retrieve the value associated with the key 'name' in a dictionary named 'my_dict'?
my_dict['name']
Both option1 and option3
my_dict.name
my_dict.get('name')