Showing 61–70 of 119 questions
What is the output of: print('Hello' + ' ' + 'World')?
A
HelloWorld
B
Hello World
C
Hello + World
D
Error
Correct Answer:
B. Hello World
EXPLANATION
String concatenation using + operator combines 'Hello', ' ', and 'World' into 'Hello World'.
Which of the following is the correct syntax for a Python comment?
A
// This is a comment
B
C
# This is a comment
D
/* This is a comment */
Correct Answer:
C. # This is a comment
EXPLANATION
Python uses the hash symbol (#) for single-line comments. The other syntaxes are used in other programming languages.
Consider the code: num = '123'. What will int(num) return?
A
123.0
B
123
C
'123'
D
Error
EXPLANATION
int(num) converts the string '123' to the integer 123. The result is an integer type.
What does the len() function return when applied to a string 'India'?
EXPLANATION
The string 'India' has 5 characters (I, n, d, i, a), so len('India') returns 5.
What will be the result of executing: print(type(5.0))?
EXPLANATION
5.0 is a floating-point number, so type(5.0) returns <class 'float'>.
In Python, which of the following is an immutable data type?
A
List
B
Dictionary
C
Tuple
D
Set
EXPLANATION
Tuples are immutable in Python, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are all mutable.
What will be the output of: print(any([False, False, True]))
A
True
B
False
C
Error
D
None
EXPLANATION
any() returns True if at least one element in the iterable is True.
Consider: x = [i**2 for i in range(4)]. What is x?
A
[0, 1, 2, 3]
B
[1, 4, 9, 16]
C
[0, 1, 4, 9]
D
[2, 4, 6, 8]
Correct Answer:
C. [0, 1, 4, 9]
EXPLANATION
List comprehension: i**2 for i in [0,1,2,3] produces [0, 1, 4, 9].
What will be the output of: d = {'a': 1, 'b': 2}; print(list(d.items()))
A
[('a', 1), ('b', 2)]
B
['a', 'b']
C
[1, 2]
D
Error
Correct Answer:
A. [('a', 1), ('b', 2)]
EXPLANATION
dict.items() returns key-value pairs as tuples, converted to a list: [('a', 1), ('b', 2)].
Which of the following will raise a TypeError in Python?
A
int('10')
B
int(10.5)
C
int('10.5')
D
int(True)
Correct Answer:
C. int('10.5')
EXPLANATION
int('10.5') raises TypeError because '10.5' is a string representation of a float, not a valid integer string.