ExamVeda
Login
Home
31
Which of the following functions does not throw an error?
Discuss
Answer & Solution
Answer: Option B
Solution:
The correct answer is Option B: ord(' ').
The ord() function in Python is used to get the Unicode code point of a character. When you pass a single character as an argument to the ord() function, it returns the Unicode code point of that character. In this case, passing a space character (' ') to the ord() function will not throw an error, as it represents a valid Unicode character. It returns the Unicode code point for the space character, which is 32.

The other options will result in errors:
Option A: ord() without any argument throws a TypeError because it requires exactly one argument.
Option C: ord(") throws a TypeError because it's missing the character argument.
Option D: ord("") throws a TypeError because it's passing an empty string as an argument, which is invalid.
32
What will be the output of the following Python function?
len(["hello",2, 4, 6])
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: 4.
The len() function in Python is used to get the length of an object, such as a list, tuple, or string. When you pass the list ["hello", 2, 4, 6] to the len() function, it returns the number of elements in the list, which is 4. Therefore, the output will be 4.
33
What is the output of the following code:
my_list = [3, 1, 4, 1]
print(sorted(my_list))
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: [1, 1, 3, 4].
The sorted() function in Python is used to sort the elements of an iterable in ascending order. When you pass the list [3, 1, 4, 1] to the sorted() function, it sorts the elements and returns a new list with the elements sorted in ascending order. Therefore, the output will be [1, 1, 3, 4].
34
Which of the following functions does not necessarily accept only iterables as arguments?
Discuss
Answer & Solution
Answer: Option C
Solution:
The correct answer is Option C: chr().
The chr() function in Python converts a Unicode code point into its corresponding character. While it typically takes an integer representing a Unicode code point as its argument, it does not necessarily accept only iterables. Instead, it can accept a wide range of integer values representing Unicode code points as arguments.

The other options:

Option A: enumerate() typically accepts iterables as arguments, as it is used to iterate over them while providing an index.
Option B: all() typically accepts iterables as arguments, as it checks if all elements in the iterable evaluate to True.
Option D: max() typically accepts iterables as arguments, as it returns the maximum element from the iterable.
35
What is the output of the following code:
my_list = [1, 2, 3]
print(list(reversed(my_list)))
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: [3, 2, 1].
The reversed() function in Python is used to reverse the elements of an iterable. When you pass the list [1, 2, 3] to the reversed() function and then convert the result to a list using list(), it returns a new list with the elements reversed, resulting in [3, 2, 1].
36
What will be the output of the following Python functions?
float('1e-003')
float('2e+003')
Discuss
Answer & Solution
Answer: Option B
Solution:
Option B: 0.001
2000.0

When the strings '1e-003' and '2e+003' are passed to the float() function, they are interpreted as scientific notation representing floating-point numbers.

'1e-003' represents 1×10−3 which is equal to 0.001.
'2e+003' represents 2×103 which is equal to 2000.0.

Therefore, the output will be 0.001 and 2000.0.
37
What will be the output of the following Python function?
ord(65)
ord(‘A’)
Discuss
Answer & Solution
Answer: Option B
Solution:
Option B: Error
65


When the argument '65' is passed to the ord() function, it's treated as an integer and not a valid Unicode character. Therefore, the function will not raise an error. Instead, it will return the Unicode code point of the character corresponding to the integer 65, which is 'A'.

Hence, the correct answer is indeed
Option B: Error
65.
38
What does the built-in function chr() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Returns a string representing a character whose Unicode code point is the integer.
The chr() function in Python is used to return a string representing a character whose Unicode code point is the integer passed as an argument. For example, chr(65) returns the string 'A' because the Unicode code point of the character 'A' is 65. Therefore, the function converts integer Unicode code points to their corresponding characters.
39
What will be the output of the following Python function?
list(enumerate([2, 3]))
Discuss
Answer & Solution
Answer: Option C
Solution:
The correct answer is Option C: [(0, 2), (1, 3)].
The enumerate() function in Python is used to add a counter to an iterable and return it as an enumerate object. When the enumerate object is converted to a list using the list() function, it returns a list of tuples where each tuple contains the index and the corresponding element of the original iterable. In this case, the input list is [2,3][2,3], and its elements are indexed starting from 0. Therefore, the output will be [(0,2),(1,3)][(0,2),(1,3)].
40
Which built-in function is used to calculate the length of a sequence like a list or string?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: len().
The len() function in Python is used to calculate the length of a sequence, such as a list or a string. It returns the number of items in the sequence. For example, len([1, 2, 3]) will return 3, as there are three elements in the list. Similarly, len("hello") will return 5, as there are five characters in the string "hello".