Showing 11–20 of 38 questions
What is the output of: print(10 // 3 + 10 % 3)?
EXPLANATION
10 // 3 = 3 (floor division), 10 % 3 = 1 (modulo). 3 + 1 = 4. Wait, let me recalculate: 10//3=3, 10%3=1, so 3+1=4. Actually: output is 4.
Which of the following is NOT a valid Python variable name?
A
_private_var
B
2nd_variable
C
variable_name
D
__dunder__
Correct Answer:
B. 2nd_variable
EXPLANATION
Variable names cannot start with a digit. '2nd_variable' is invalid because it begins with '2'. Valid names start with a letter or underscore.
What will be the output of: print(10 // 3)?
EXPLANATION
The floor division operator (//) returns the quotient without decimal places. 10 // 3 = 3.
Which method is used to add an element to a list in Python?
A
add()
B
append()
C
insert()
D
push()
Correct Answer:
B. append()
EXPLANATION
The append() method adds an element to the end of a list. insert() requires index specification, add() is for sets.
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.