w3resource

Python: Documentation of a built-in-function


4. Access builtins module: Import abs(), show docs & absolute value

'builtins' module provides direct access to all 'built-in' identifiers of Python.
Write a Python program that imports the abs() function using the builtins module, displays the documentation of the abs() function and finds the absolute value of -155.

Sample Solution:

Python Code:

import builtins 
help(builtins.abs)
print(builtins.abs(-155))

Sample Output:

Help on built-in function abs in module builtins:

abs(x, /)
    Return the absolute value of the argument.

155

Flowchart:

Flowchart: Documentation of a built-in-function.

For more Practice: Solve these Related Problems:

  • Write a Python program to import the abs() function from the builtins module and then print its __doc__ attribute.
  • Write a Python program to use the abs() function imported from builtins to calculate the absolute value of a negative number and print the result.
  • Write a Python program to import multiple built-in functions (e.g., abs, len) from builtins and display their documentation.
  • Write a Python program to access the builtins module via __import__ and then call abs() on a user-supplied number.

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to create an instance of a specified class and display the namespace of the said instance.
Next: Define a Python function student(). Using function attributes display the names of all arguments.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.