ExamVeda
Login
Home
1
Which built-in function is used to find the smallest item in an iterable?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: min().
The min() function is used to find the smallest item in an iterable, such as a list, tuple, or set.
It takes an iterable as an argument and returns the smallest item.
For example:
numbers = [5, 2, 8, 1, 6]
smallest_number = min(numbers)
print(smallest_number)  # Output: 1
2
What does the built-in function round() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Rounds a floating-point number to the nearest integer.
The round() function in Python is used to round a floating-point number to the nearest integer.
It takes one or two arguments. If given one argument, it rounds the number to the nearest integer.
If given two arguments, it rounds the first argument to the number of decimal places specified by the second argument.
For example:
num1 = 3.7
num2 = 9.2
rounded_num1 = round(num1)
rounded_num2 = round(num2)
print(rounded_num1)  # Output: 4
print(rounded_num2)  # Output: 9
3
What does the built-in function max() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Returns the largest item in an iterable.
The max() function in Python is used to find the largest item in an iterable, such as a list, tuple, or set.
It takes one or more arguments and returns the largest item.
For example:
numbers = [5, 2, 8, 1, 6]
largest_number = max(numbers)
print(largest_number)  # Output: 8
4
Which built-in function is used to check if all elements in an iterable are true?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: all().
The all() function in Python is used to check if all elements in an iterable are true.
It takes an iterable as an argument and returns True if all elements in the iterable are true, otherwise False.
For example:
my_list = [True, True, True]
result = all(my_list)
print(result)  # Output: True
5
What does the built-in function enumerate() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Returns an enumerate object that produces pairs of index and value.
The enumerate() function in Python is used to iterate over a sequence while keeping track of the index of each item.
It takes an iterable as an argument and returns an enumerate object that produces tuples containing the index and value of each item in the iterable.
For example:
my_list = ['a', 'b', 'c']
for index, value in enumerate(my_list):
    print(index, value)
# Output:
# 0 a
# 1 b
# 2 c
6
Which built-in function is used to convert a value to an integer?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: int().
The int() function in Python is used to convert a value to an integer.
It can convert a string representing a number, a float, or even another integer to an integer data type.
For example:
num_str = "10"
num_float = 3.14
converted_str = int(num_str)
converted_float = int(num_float)
print(converted_str)     # Output: 10
print(converted_float)   # Output: 3
7
What does the built-in function bool() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Converts a value to a boolean value.
The bool() function in Python is used to convert a value to a boolean value.
It returns True if the value is true, and False if the value is false.
For example:
print(bool(0))      # Output: False
print(bool(10))     # Output: True
print(bool([]))     # Output: False
print(bool([1,2]))  # Output: True
8
Which built-in function is used to calculate the absolute value of a number?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: abs().
The abs() function in Python is used to calculate the absolute value of a number.
It returns the magnitude of a numeric value without regard to its sign.
For example:
print(abs(-5))   # Output: 5
print(abs(3.14)) # Output: 3.14
9
What is the purpose of the built-in function dir()?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Returns a list of attributes and methods of an object.
The dir() function in Python is used to return a list of attributes and methods of an object.
When called without an argument, it returns the list of names in the current local scope.
For example:
my_list = [1, 2, 3]
print(dir(my_list))  # Output: ['__add__', '__class__', '__contains__', ...]
10
What is the output of the following code:
my_string = "Hello, World!"
print(my_string.upper())
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: "HELLO, WORLD!".
The upper() method in Python is used to convert all the characters in a string to uppercase.
So, when you call upper() on the string "Hello, World!", it converts all the letters to uppercase.
my_string = "Hello, World!"
print(my_string.upper())  # Output: "HELLO, WORLD!"