-
web.groovymark@gmail.com
- November 29, 2024
Question 41
Which operator is used to get the remainder of a division in Python?
a) /
b) %
c) **
d) //
Correct Answer: b) %
Explanation: The modulus operator % returns the remainder of a division.
Question 42
What does str(5) return in Python?
a) The string ‘5’
b) The integer 5
c) The float 5.0
d) The list [5]
Correct Answer: a) The string '5'
Explanation: The str() function converts an integer or float to a string.
Question 43
Which method can be used to convert a string to lowercase in Python?
a) upper()
b) capitalize()
c) lower()
d) title()
Correct Answer: c) lower()
Explanation: The lower() method converts all characters in a string to lowercase.
Question 44
Which keyword is used to handle exceptions in Python?
a) try
b) throw
c) except
d) finally
Correct Answer: c) except
Explanation: The except keyword is used to handle exceptions in Python.
Question 45
What will be the output of print(4 % 2)?
a) 2
b) 0
c) 1
d) 4
Correct Answer: b) 0
Explanation: 4 % 2 returns 0 because 4 is divisible by 2 with no remainder.
Question 46
Which function in Python generates a range of numbers?
a) range()
b) list()
c) tuple()
d) len()
Correct Answer: a) range()
Explanation: The range() function generates a sequence of numbers.
Question 47
What is the output of the following code: print(10 // 3)?
a) 3.0
b) 3
c) 3.33
d) 4
Correct Answer: b) 3
Explanation: // is the floor division operator, which returns the largest integer less than or equal to the division result.
Question 48
Which method would you use to convert a string to an integer in Python?
a) str()
b) int()
c) float()
d) bool()
Correct Answer: b) int()
Explanation: The int() method converts a valid string or float to an integer.
Question 49
What is the purpose of the elif statement in Python?
a) To check multiple conditions
b) To end a loop
c) To start a new block of code
d) To convert data types
Correct Answer: a) To check multiple conditions
Explanation: The elif statement allows the program to test multiple conditions in an if-elif-else structure.
Question 50
Which keyword is used to define a class in Python?
a) def
b) class
c) object
d) new
Correct Answer: b) class
Explanation: The class keyword is used to define a class in Python, which is a blueprint for creating objects.