Explanation: The function chr () only accepts integers as parameters. The ord () function only accepts the data type string. Min () and max () functions can accept both floating point and integer parameters.
Question 2: Suppose there is a list: l = [2,3,4]. If you want to print this list in reverse order, which of the following methods should you use?
reverse (l)
list (reverse [(l)])
reversed (l)
list (reversed (l))
Explanation: The reversed () function can be used to reverse the elements of a list. This function only accepts iterable as a parameter. To print the result as a list we use: list (reversed (l)). The output will be: [4,3,2].
Question 3: What is the output of the following function?
float(' -12345n')
Note: the number of spaces before that number is 5.
-12345.0 (5 spaces before the number)
-12345.0
Lỗi
-12345.000000000 . (infinite decimal number)
Explanation: The float () function will delete all spaces and convert integers to floating-point numbers. Therefore, the result will be: -12345.0.
Question 4: What is the result of the function shown below?
ord(65) ord('A')
A 65
Lỗi 65
A Lỗi
Lỗi Lỗi
Explanation: ord () function is used to return the ASCII value of the letter passed to it as a parameter. Therefore, the first function leads to an error and the output of the second function is 65.
Question 5: What is the result of the following function?
float('-infinity') float('inf')
-Inf inf
–Infinity inf
Lỗi Lỗi
Lỗi Junk value
Question 6: Which of the following functions will not cause errors when not passing parameters to it?
min ()
divmod ()
all ()
float ()
Explanation: The built-in functions all (), divmod (), min () will get an error if no parameters passed to them and float () can still function normally. In case no parameters are passed, float will return 0.0
Question 7: What is the result of the following expression?
hex(15)
f
0xF
0Xf
0xf
Explanation: Hex () function converts Integer to Hexadecimal, lowercase. Therefore the output of hex function (15) is 0xf.
Question 8: Which of the following functions does not cause errors?
ord ()
ord ('')
ord (")
ord ("")
Explanation: The ord function has parameters that are characters, so the ord (), ord (") and ord (" ") will cause an error, but the ord ('') function does not cause an error because we are communicating number is a space, ord ('') output is 32 (ASCII value corresponds to space).
Question 9: What is the result of the function shown below?
len(["hello",2, 4, 6])
4
3
Lỗi
6
Explanation: The len () function returns the length of the object, so the output of the function shown above is 4.
Question 10: What is the result of the following function?
oct(7) oct('7')
Lỗi 07
07 Lỗi
0o7 Lỗi
07 0o7
Explanation: The oct () function is used to convert its parameter to octal. This function does not accept strings. Therefore, the second function leads to an error while the output of the first function is 0o7.