What function in Python is used to get input from the user?
a) print() b) input() c) len() d) int()
Correct Answer: b) input()
Explanation: The input() function is used to get user input as a string.
Question 02
What is a string literal in Python?
a) Text enclosed in quotes b) A list of numbers c) A comment line d) A mathematical operation
Correct Answer: a) Text enclosed in quotes
Explanation: A string literal is text enclosed in single or double quotes, representing text data.
Question 03
How can you keep multiple print() statements on the same line in Python?
a) Use \\n b) Use end=’ ‘ c) Use print() without parentheses d) Use input()
Correct Answer: b) Use end=' '
Explanation: The end=' ' parameter prevents the print() function from moving to the next line
Question 04
What is the symbol for an exponent operator in Python?
a) * b) / c) ** d) %
Correct Answer: c) **
Explanation: The ** operator is used to perform exponentiation in Python, such as x ** y.
Question 05
Which function returns the number of elements in a list or string in Python?
a) int() b) len() c) print() d) str()
Correct Answer: b) len()
Explanation: The len() function returns the length of a list, string, or other iterable.
Question 06
What type of loop repeats as long as a specified condition is true in Python?
a) for loop b) while loop c) do-while loop d) foreach loop
Correct Answer: b) while loop
Explanation: A while loop repeatedly executes code as long as its condition evaluates to True.
Question 07
Which function converts a string to an integer in Python?
a) int() b) float() c) str() d) input()
Correct Answer: a) int()
Explanation: The int() function converts a valid string or float to an integer.
Question 08
What is a syntax error in Python?
a) Error in logic b) Error in code formatting c) Violation of programming language rules d) User input error
Correct Answer: c) Violation of programming language rules
Explanation: A syntax error occurs when the code does not conform to the syntax rules of the language.
Question 09
What does \\n represent in Python strings?
a) Tab space b) Newline c) Backslash d) Indent
Correct Answer: b) Newline
Explanation:\\n is an escape sequence that moves the output to the next line.
Question 10
What error occurs when a program attempts an impossible operation, such as dividing by zero?
a) Syntax error b) Runtime error c) Logic error d) Type error
Correct Answer: b) Runtime error
Explanation: A runtime error occurs during program execution when an operation is not possible, like dividing by zero.
Question 11
What is the purpose of indentation in Python code?
a) To mark comments b) To separate code blocks c) To format strings d) To declare variables
Correct Answer: b) To separate code blocks
Explanation: Python uses indentation to define code blocks, such as those in loops and functions.
Question 12
What does the float() function do in Python?
a) Converts a string to an integer b) Converts an integer to a floating-point number c) Converts a float to an integer d) Formats numbers with two decimal places
Correct Answer: b) Converts an integer to a floating-point number
Explanation: The float() function converts integers or strings to floating-point numbers.
Question 13
What is the result of 5 // 2 in Python?
a) 2.5 b) 3 c) 2 d) 5
Correct Answer: c) 2
Explanation:// is the floor division operator, which returns the largest integer less than or equal to the division result.
Question 14
Which Python keyword is used to define a function?
a) func b) def c) function d) define
Correct Answer: b) def
Explanation: The def keyword is used to define a new function in Python
Question 15
What does the return statement do in a function?
a) Exits the function b) Stops the loop c) Returns a value to the caller d) Declares a variable
Correct Answer: c) Returns a value to the caller
Explanation: The return statement exits the function and sends a value back to where the function was called.
Question 16
What does pass do in Python code?
a) It executes a print statement b) It skips the current iteration of a loop c) It is a placeholder that does nothing d) It raises an exception
Correct Answer: c) It is a placeholder that does nothing
Explanation: The pass statement is used when a statement is required syntactically but no action is needed.
Question 17
Which Python function can round a floating-point number up to the nearest integer?
a) ceil() b) floor() c) round() d) abs()
Correct Answer: a) ceil()
Explanation: The ceil() function from the math module rounds a floating-point number up to the next whole number.
Question 18
What is a list in Python?
a) A collection of unique elements b) An immutable sequence of elements c) A mutable container with ordered elements d) A key-value pair container
Correct Answer: c) A mutable container with ordered elements
Explanation: A list is a mutable collection in Python, meaning its contents can be modified.
Question 19
Which operator is used for string concatenation in Python?
a) * b) + c) – d) /
Correct Answer: b) +
Explanation: The + operator is used to concatenate two strings in Python.
Question 20
What does the len() function return when applied to a list?
a) The sum of all elements b) The type of elements in the list c) The number of elements in the list d) The last element in the list
Correct Answer: c) The number of elements in the list
Explanation: The len() function returns the total number of elements in a list or string.