ExamVeda
Login
Home
21
What will be the output of the following Python function?
oct(7)
oct(‘7’)
Discuss
Answer & Solution
Answer: Option C
Solution:
The oct() function in Python converts an integer to an octal string. When passed an integer argument, it returns the octal representation prefixed with '0o'. However, when passed a string argument, it tries to convert the string to an integer first, and if it fails, it raises a ValueError. Therefore, the first call to oct(7) returns '0o7', while the second call to oct('7') raises an error.
22
What is the output of the following code:
my_list = [1, 2, 3, 4]
print(sum(my_list))
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: 10.
The sum() function in Python is used to sum up all the values in an iterable, such as a list. When you pass the list [1, 2, 3, 4] to the sum() function, it adds up all the elements in the list and returns the total sum, which is 10.
23
What will be the output of the following Python functions?
chr(‘97’)
chr(97)
Discuss
Answer & Solution
Answer: Option C
Solution:
For the first call chr('97'), the function chr() expects an integer representing a Unicode code point, not a string. When it receives the string '97', it attempts to convert it to an integer, but it raises a TypeError because it cannot directly convert a string to an integer in this context. Hence, it results in an error.

For the second call chr(97), the argument passed is an integer, which represents the Unicode code point for the character 'a'. Therefore, this call to chr() returns the character 'a'.

So, the output is "Error" for the first call and "a" for the second call.
24
What is the output of the following code:
my_list = [5, 8, 2, 6]
print(max(my_list))
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: 8.
The max() function in Python is used to find the maximum value among the elements of an iterable, such as a list. When you pass the list [5, 8, 2, 6] to the max() function, it returns the maximum value from the list, which is 8.
25
What will be the output of the following code:
my_string = " Hello, World! "
print(my_string.strip())
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: "Hello, World!".
The strip() function in Python is used to remove leading and trailing whitespace (spaces, tabs, and newline characters) from a string. When you call strip() on the string " Hello, World! ", it removes the leading and trailing spaces and returns the modified string "Hello, World!".
26
What will be the output of the following code:
my_string = "Hello, World!"
print(my_string.lower())
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: "hello, world!".
The lower() function in Python is used to convert all characters in a string to lowercase. When you call lower() on the string "Hello, World!", it converts all uppercase letters to lowercase, resulting in the string "hello, world!".
27
What will be the output of the following Python function?
complex(1+2j)
Discuss
Answer & Solution
Answer: Option D
Solution:
The correct answer is Option D: 1+2j.
The complex() function in Python is used to create a complex number from real and imaginary parts. When you pass the expression 1+2j to the complex() function, it returns the complex number with real part 1 and imaginary part 2j.
28
Which built-in function is used to convert a value to a string?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: str().
The str() function in Python is used to convert a value to a string.
It can convert various types of values, such as integers, floats, booleans, and even other data structures like lists and dictionaries, into their string representations.
For example:
x = 10
y = 3.14
z = True

str_x = str(x)
str_y = str(y)
str_z = str(z)

print(str_x)  # Output: '10'
print(str_y)  # Output: '3.14'
print(str_z)  # Output: 'True'
29
What does the built-in function type() do in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is Option A: Returns the type of an object.
The type() function in Python is used to get the type of an object. It returns the type of the object passed as an argument. This can be useful for checking the type of variables or objects during runtime.
For example:
x = 10
y = "Hello"
z = [1, 2, 3]

print(type(x))  # Output: 
print(type(y))  # Output: 
print(type(z))  # Output: 
30
What will be the output of the following Python function?
float('   -12345\n')
(Note that the number of blank spaces before the number is 5)
Discuss
Answer & Solution
Answer: Option B
Solution:
The correct answer is Option B: -12345.0.
The float() function in Python is used to convert a string or a number to a floating-point number. When you pass the string ' -12345\n' (which includes leading and trailing whitespace characters) to the float() function, it strips the leading and trailing whitespace and converts the remaining characters to a floating-point number. In this case, it converts '-12345' to a float, resulting in -12345.0.