Showing 71–80 of 100 questions
in Basics & Syntax
What will be the output of: x = [1, 2, 3]; x.append(4); print(len(x))?
EXPLANATION
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(max([3, 1, 4, 1, 5, 9, 2, 6]))?
EXPLANATION
The max() function returns the largest element in the list, which is 9.
Which of the following is a valid variable name in Python?
A
2variable
B
var-iable
C
var_iable
D
var iable
Correct Answer:
C. var_iable
EXPLANATION
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(abs(-5) + abs(3))?
EXPLANATION
abs(-5) = 5 and abs(3) = 3. Therefore, 5 + 3 = 8.
What will be the output of: print(type({}))?
EXPLANATION
Empty curly braces {} create an empty dictionary, not a set. To create an empty set, use set().
What will be the output of: x = 5; y = x; y = 10; print(x)?
EXPLANATION
x and y are separate variables. Assigning y = 10 doesn't change x, which remains 5.
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.