How can you retrieve the value associated with the key 'name' in a dictionary named 'my_dict'?
Both option1 and option3
my_dict.name
my_dict['name']
my_dict.get('name')
Which function is used to convert a string to an integer in Python?
bool()
float()
int()
str()
What is the correct way to create a string literal containing both single and double quotes in Python?
'He said, "Hello!"'
"He said, 'Hello!'"
Both option 1 and 2 are correct
What will the following code print?
set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.intersection(set2))
Error
{3}
{1, 2, 3, 4, 5}
{1, 2, 4, 5}
Which statement is true about the else block in a while loop?
else
while
The else keyword cannot be used with a while loop.
It executes only if the loop contains a break statement.
break
It always executes after the loop finishes.
It executes only if the loop condition becomes false.
What is the value of the expression: '5' + '3'?
'5' + '3'
15
53
8
What is the output of this code?
i = 0 while i < 3: print(i) i += 2
0 1 2
0 2
Infinite loop
0 1
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 is the primary purpose of using functions in Python?
To increase the execution speed of the program.
To define data structures like lists and dictionaries.
To make the code more readable and organized.
To reduce the memory consumption of the program.
What is the time complexity of checking if an element is present in a Python set?
O(log n)
O(n log n)
O(n)
O(1)