Multiple choice quiz about Python - Part 8

Python's built-in function of multiple-choice questions helps you update and review useful knowledge for your work and learn your Python programming language.
  1. Question 1: Which of the following functions only accepts integers as parameters?
    1. ord ()
    2. min ()
    3. chr ()

    4. any ()
    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.
  2. 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?
    1. reverse (l)
    2. list (reverse [(l)])
    3. reversed (l)
    4. 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].
  3. Question 3: What is the output of the following function?
     float(' -12345n') 
    Note: the number of spaces before that number is 5.
    1. -12345.0 (5 spaces before the number)
    2. -12345.0
    3. Lỗi
    4. -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.
  4. Question 4: What is the result of the function shown below?
     ord(65) 
    ord('A')
    1. A
      65
    2. Lỗi
      65
    3. A
      Lỗi
    4. 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.
  5. Question 5: What is the result of the following function?
     float('-infinity') 
    float('inf')
    1. -Inf
      inf
    2. –Infinity
      inf
    3. Lỗi
      Lỗi
    4. Lỗi
      Junk value
  6. Question 6: Which of the following functions will not cause errors when not passing parameters to it?
    1. min ()
    2. divmod ()
    3. all ()
    4. 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
  7. Question 7: What is the result of the following expression?
     hex(15) 
    1. f
    2. 0xF
    3. 0Xf
    4. 0xf
    Explanation: Hex () function converts Integer to Hexadecimal, lowercase. Therefore the output of hex function (15) is 0xf.
  8. Question 8: Which of the following functions does not cause errors?
    1. ord ()
    2. ord ('')
    3. ord (")
    4. 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).
  9. Question 9: What is the result of the function shown below?
     len(["hello",2, 4, 6]) 
    1. 4
    2. 3
    3. Lỗi
    4. 6
    Explanation: The len () function returns the length of the object, so the output of the function shown above is 4.
  10. Question 10: What is the result of the following function?
     oct(7) 
    oct('7')
    1. Lỗi
      07
    2. 07
      Lỗi
    3. 0o7
      Lỗi
    4. 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.
5 ★ | 1 Vote