What is the correct way to create a string literal containing both single and double quotes in Python?
"He said, 'Hello!'"
Both option 1 and 2 are correct
'He said, "Hello!"'
What is the maximum number of arguments a lambda function can take?
Unlimited
1
255
2
What will the following Python code print to the console?
name = input("Enter your name: ") print("Hello,", name)
It will print nothing.
Hello, [user's input]
Enter your name:
Enter your name: Hello, [user's input]
How can you convert the integer 10 to a string in Python?
10
10.to_string()
toString(10)
str(10)
int_to_str(10)
Which statement is true about the else block in a while loop?
else
while
It executes only if the loop contains a break statement.
break
It executes only if the loop condition becomes false.
It always executes after the loop finishes.
The else keyword cannot be used with a while loop.
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
1 2 3 4
0 1 2 4 5
What is the purpose of the break statement in a loop?
It prints the current value of the loop variable.
It defines a new variable within the loop.
It exits the loop entirely.
It skips the current iteration and continues to the next.
How many times will the word 'Hello' be printed?
i = 0 while i < 3: print('Hello') i += 1
3
Infinitely
4
Which loop is best suited for iterating over a sequence of elements like a list?
for loop
for
None of the above
Both are equally suitable
while loop
How many times will the following loop iterate?
for i in range(3, 8): print(i)
7
8
5