What is the output of: print(10 // 3)?
The floor division operator (//) returns the quotient rounded down to the nearest integer. 10 // 3 = 3.
Which of the following is an immutable data type in Python?
Tuples are immutable, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are mutable.
What will be the output of: len('hello world')?
The len() function counts all characters including the space. 'hello world' has 11 characters (including 1 space).
Which of the following will correctly concatenate two strings 'Hello' and 'World'?
The + operator concatenates strings in Python. Other operators don't perform string concatenation.
What will be the output of: x = 5; y = x; y = 10; print(x)?
x and y are separate variables. Assigning y = 10 doesn't change x, which remains 5.
Advertisement
What will be the output of: print(type({}))?
Empty curly braces {} create an empty dictionary, not a set. To create an empty set, use set().
What will be the output of: print(abs(-5) + abs(3))?
abs(-5) = 5 and abs(3) = 3. Therefore, 5 + 3 = 8.
Which of the following is a valid variable name in Python?
Variable names can contain letters, digits, and underscores, but cannot start with a digit or contain hyphens or spaces.
What will be the output of: print(max([3, 1, 4, 1, 5, 9, 2, 6]))?
The max() function returns the largest element in the list, which is 9.
What will be the output of: x = [1, 2, 3]; x.append(4); print(len(x))?
append() adds an element to the list. After adding 4, the list has 4 elements, so len(x) = 4.
What will be the output of: print('a' * 3 + 'b' * 2)?
'a' * 3 produces 'aaa' and 'b' * 2 produces 'bb'. Concatenating gives 'aaabb'.
What will be the output of: x = '10'; y = int(x); print(y + 5)?
int(x) converts the string '10' to integer 10. Adding 5 gives 15 (integer addition).
Which of the following code snippets will execute without raising a NameError?
Only option B defines x before using it. Other options reference undefined variables, causing NameError.
What will be the output of: print(all([True, True, True]))?
all() returns True if all elements are True. Since all three elements are True, the output is True.
Consider the following code:
x = [1, 2, 3]
y = x[::-1]
print(y)
What will be the output?
The slice notation [::-1] reverses the list. [1, 2, 3] reversed is [3, 2, 1].
What will be the output of: print({1, 2, 3} | {3, 4, 5})?
The | operator performs set union, combining all unique elements from both sets. Result is {1, 2, 3, 4, 5}.
What is the correct way to create a dictionary in Python?
Dictionaries in Python use curly braces with key-value pairs separated by colons.
Which of the following statements about Python tuples is correct?
Tuples are immutable sequences in Python, meaning their contents cannot be changed once created.
What will be the output of: x = 5; y = 10; print(x == y)
The comparison operator == checks if x equals y. Since 5 ≠ 10, the result is False.
What does len() function return when applied to a string?
The len() function returns the number of characters (length) in a string.