Showing 31–38 of 38 questions
Which of the following keywords is used to create a function in Python?
A
function
B
def
C
func
D
define
EXPLANATION
The 'def' keyword is used to define a function in Python. Other options are not valid Python keywords.
What will be the output of: print(type(5 / 2))?
EXPLANATION
The division operator (/) in Python 3 always returns a float, even if both operands are integers.
Which statement about Python comments is correct?
A
Comments must be on their own line
B
Comments start with # and can be inline or on separate lines
C
Comments use // like in C++
D
Multiple line comments use /* */
Correct Answer:
B. Comments start with # and can be inline or on separate lines
EXPLANATION
Python comments start with # and can appear anywhere. Multi-line comments use triple quotes or multiple # symbols.
What will be the output of: len('Python')?
EXPLANATION
The string 'Python' has 6 characters: P, y, t, h, o, n. The len() function returns the number of characters.
Which keyword is used to create a function in Python?
A
function
B
def
C
func
D
define
EXPLANATION
The 'def' keyword is used to define functions in Python. It is followed by the function name and parameters.
What will be the output of: print(type(5.0))?
EXPLANATION
5.0 is a floating-point number in Python. The type() function returns <class 'float'> for decimal numbers.
Which of the following is NOT a valid Python identifier?
A
_variable
B
variable2
C
2variable
D
var_name
Correct Answer:
C. 2variable
EXPLANATION
Python identifiers cannot start with a digit. They must begin with a letter or underscore.
What is the correct way to create a variable in Python?
A
variable_name = value
B
$variable_name = value
C
variable-name = value
D
variable name = value
Correct Answer:
A. variable_name = value
EXPLANATION
Python variables are created using the assignment operator (=) with valid identifiers containing letters, digits, and underscores.