Showing 91–100 of 100 questions
in Basics & Syntax
What will be the output of: 'Hello' * 2?
A
'HelloHello'
B
Error
C
'Hello' concatenated twice
D
HelloHello
Correct Answer:
D. HelloHello
EXPLANATION
String multiplication repeats the string. 'Hello' * 2 produces 'HelloHello'.
Which method is used to add an element to a Python list?
A
add()
B
append()
C
insert()
D
Both B and C
Correct Answer:
D. Both B and C
EXPLANATION
append() adds an element at the end, while insert() adds at a specific position. Both are valid methods.
Which of the following will create an empty dictionary?
A
{}
B
{:}
C
dict()
D
Both A and C
Correct Answer:
D. Both A and C
EXPLANATION
{} and dict() both create empty dictionaries. {} is more concise while dict() is explicit.
Which operator is used for integer division in Python 3?
EXPLANATION
The '//' operator performs floor division and returns an integer, while '/' returns a float in Python 3.
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 data type is immutable in Python?
A
List
B
Dictionary
C
Tuple
D
Set
EXPLANATION
Tuples are immutable sequences in Python. Once created, their elements cannot be modified, unlike lists.
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.