What is a lambda function in Python?
A small, anonymous function defined using the 'lambda' keyword.
A function that recursively calls itself.
A function defined using the 'def' keyword.
A function that takes another function as an argument.
Which method is used to add a new key-value pair to a dictionary?
append()
insert()
add()
update()
What is the correct way to add a new key-value pair to an existing dictionary in Python?
my_dict.insert('city', 'New York')
my_dict + {'city': 'New York'}
my_dict.append('city', 'New York')
my_dict['city'] = 'New York'
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 correct way to write and run a Python script named 'my_script.py' from the command line?
run my_script.py
execute my_script.py
python my_script.py
python run my_script.py
What will the following Python code snippet print?
def greet(name): print(f"Hello, {name}!") greet("Alice")
greet("Alice")
Hello, Alice!
Hello, name!
An error message.
What is the purpose of the break statement in a loop?
break
It defines a new variable within the loop.
It exits the loop entirely.
It skips the current iteration and continues to the next.
It prints the current value of the loop variable.
What will the following code snippet print?
tuple1 = (1, 2, 3) tuple2 = (4, 5, 6) print(tuple1 + tuple2)
(1, 2, 3)(4, 5, 6)
Error
[1, 2, 3, 4, 5, 6]
(1, 2, 3, 4, 5, 6)
Which assignment operator in Python is used to perform floor division and assign the result?
//=
/=
%=
=
How many times will the following loop iterate?
for i in range(1, 5): print(i)
5
4
1
Infinitely