ExamVeda
Login
Home
51
The function pow(x,y,z) is evaluated as:
Discuss
Answer & Solution
Answer: Option C
Solution:
The pow() function in Python is used to raise a number x to the power of y, optionally taking a modulo z. The expression pow(x, y, z) is equivalent to (x ** y) % z, which means x raised to the power of y, then the result is taken modulo z.
52
What is the purpose of the built-in function abs()?
Discuss
Answer & Solution
Answer: Option A
Solution:
The abs() function in Python returns the absolute value of a number, which is the distance of the number from zero on the number line, regardless of its sign.
53
What does the built-in function sorted() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The sorted() function in Python takes an iterable as an argument and returns a new sorted list containing all items from the iterable in ascending order.
54
What will be the output of the following code:
my_string = "Hello, World!"
print(my_string.replace("Hello", "Hi"))
Discuss
Answer & Solution
Answer: Option A
Solution:
The replace() function in Python replaces all occurrences of a specified substring with another substring in a given string. In this case, "Hello" is replaced with "Hi" in the string "Hello, World!", resulting in "Hi, World!".
55
Which of the following functions accepts only integers as arguments?
Discuss
Answer & Solution
Answer: Option B
Solution:
The min() function in Python is used to find the minimum value among its arguments. It can accept multiple arguments, and they can be integers, floats, or strings. However, it does not accept non-numeric types like lists or tuples as arguments.
56
What will be the output of the following Python function?
divmod(10.5,5)
divmod(2.4,1.2)
Discuss
Answer & Solution
Answer: Option C
Solution:
The divmod() function in Python returns a tuple containing the quotient and remainder when dividing the first argument by the second. In the first case, divmod(10.5, 5) returns (2.0, 0.5) because 10.5 divided by 5 results in 2.0 with a remainder of 0.5. In the second case, divmod(2.4, 1.2) returns (2.0, 0.0) because 2.4 divided by 1.2 results in 2.0 with no remainder.
57
What will be the output of the following code:
my_list = [1, 2, 3, 4]
print(len(my_list))
Discuss
Answer & Solution
Answer: Option A
Solution:
The len() function in Python is used to find the number of elements in an object. In this case, len(my_list) will return the length of the list my_list, which contains four elements [1, 2, 3, 4]. Therefore, the output will be 4.
58
The function complex('2-3j') is valid but the function complex('2 - 3j') is invalid.
Discuss
Answer & Solution
Answer: Option A
Solution:
The complex() function in Python can accept a string argument representing a complex number in the form 'a+bj' or 'a-bj', where a and b are real numbers. In the first case, '2-3j', there are no spaces between the real and imaginary parts, so it is valid. However, in the second case, '2 - 3j', there is a space between 2 and -, making it an invalid input for the complex() function.
59
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
Discuss
Answer & Solution
Answer: Option D
Solution:
To print a list in reverse order in Python, you can use the reversed() function, which returns an iterator that yields items in reverse order. However, to display it as a list, you need to convert the iterator back to a list using the list() function. Therefore, list(reversed(l)) is the correct method to print the list l in reverse order.