Showing 21–30 of 38 questions
What will be the output of: print(type(3.14))
EXPLANATION
3.14 is a floating-point number, so type() returns <class 'float'>.
What does len() function return when applied to a string?
A
The ASCII value of first character
B
The number of characters in the string
C
The memory size of the string
D
The index of last character
Correct Answer:
B. The number of characters in the string
EXPLANATION
The len() function returns the number of characters (length) in a string.
What will be the output of: x = 5; y = 10; print(x == y)
A
True
B
False
C
Error
D
None
EXPLANATION
The comparison operator == checks if x equals y. Since 5 ≠ 10, the result is False.
Which of the following statements about Python tuples is correct?
A
Tuples are mutable and can be modified after creation
B
Tuples are immutable and cannot be modified after creation
C
Tuples use square brackets for declaration
D
Tuples automatically convert to lists when assigned
Correct Answer:
B. Tuples are immutable and cannot be modified after creation
EXPLANATION
Tuples are immutable sequences in Python, meaning their contents cannot be changed once created.
What is the correct way to create a dictionary in Python?
A
d = {1: 'a', 2: 'b'}
B
d = [1: 'a', 2: 'b']
C
d = (1: 'a', 2: 'b')
D
d = {1; 'a'; 2; 'b'}
Correct Answer:
A. d = {1: 'a', 2: 'b'}
EXPLANATION
Dictionaries in Python use curly braces with key-value pairs separated by colons.
Which of the following will correctly concatenate two strings 'Hello' and 'World'?
A
'Hello' + 'World'
B
'Hello' - 'World'
C
'Hello' & 'World'
D
'Hello' | 'World'
Correct Answer:
A. 'Hello' + 'World'
EXPLANATION
The + operator concatenates strings in Python. Other operators don't perform string concatenation.
What will be the output of: len('hello world')?
EXPLANATION
The len() function counts all characters including the space. 'hello world' has 11 characters (including 1 space).
Which of the following is an immutable data type in Python?
A
list
B
dictionary
C
tuple
D
set
EXPLANATION
Tuples are immutable, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are mutable.
What is the output of: print(10 // 3)?
EXPLANATION
The floor division operator (//) returns the quotient rounded down to the nearest integer. 10 // 3 = 3.
What will be the output of: print("Python"[2:5])?
EXPLANATION
String slicing [2:5] extracts characters from index 2 to 4 (5 is exclusive). 'Python'[2:5] = 'yth'.