Python Programming – Built-in Functions

The functions are already provided by Python are called built-in functions. The programmer can use built-in functions readily without any additional effort to code that function. The functions, which we have already used in previous chapters such as print( ), abs ( ), random ( ), range ( ), print ( ), input ( ), eval ( ), etc. In Python version 3.5.1. 68 built-in functions are available (which may vary depending on the different versions). The built-in functions are listed in Table 6.1., with the description of each.

Built-in Function

Description

abs() Returns the absolute value of a number.
all() Returns True if all elements of the iterable are true (or if the iterable is empty).
any() Returns True if any element of the iterable is true. If the iterable is empty, return False.
ascii() Returns a string containing a printable representation of an object, but escape the non­ASCII characters.
bin() Converts an integer number to a binary string.
bool() Converts a value to a Boolean.
Bytearray( ) Returns a new array of bytes.
Bytes ( ) Returns a new “bytes” object.
callable() Returns True if the object argument appears callable, False if not.
chr() Returns the string representing a character.
Classmethod( ) Returns a class method for the function.
compile() Compiles the source into a code or AST object.
complex() Creates a complex number or converts a string or number to a complex number.
delattr() Deletes the named attribute of an object.
dict() Creates a new dictionary.
dir() Returns the list of names in the current local scope.
divmod() Returns a pair of numbers consisting of quotient and remainder when using integer division.
enumerate() Returns an enumerate object.
eval() The argument is parsed and evaluated as a Python expression.
exec() Dynamic execution of Python code.
filter() Constructs an iterator from elements of iterable for which function returns true.
Float() Converts a string or a number to floating-point.
format() Converts a value to a “formatted” representation.
frozenset() Returns a new frozenset object.
getattr() Returns the value of the named attribute of an object.
globals() Returns a dictionary representing the current global symbol table.
hasattr() Returns True if the name is one of the object’s attributes.
hash() Returns the hash value of the object.
help() Invokes .the built-in help system.
hex() Converts an integer number to a hexadecimal string.
id() Returns the “identity” of an object.
input() Reads a line from input, converts it to a string (stripping a trailing newline), and returns that.
int() Converts a number or string to an integer.

Before calling any of the built-in functions the appropriate module must be imported first in the Python script by using the import command, otherwise, the module does not get executed. For example for using mathematical functions such as pow(), sqrt(), abs(), the math module is required to be imported beforehand the program code.

Python Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *