0% found this document useful (0 votes)
2 views

built-in functions

The document provides a comprehensive overview of various built-in Python functions, detailing their purpose, required arguments, and return values. Each function is described succinctly, covering functionalities such as type conversion, data structure manipulation, and mathematical operations. This serves as a reference guide for understanding and utilizing Python's built-in capabilities.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

built-in functions

The document provides a comprehensive overview of various built-in Python functions, detailing their purpose, required arguments, and return values. Each function is described succinctly, covering functionalities such as type conversion, data structure manipulation, and mathematical operations. This serves as a reference guide for understanding and utilizing Python's built-in capabilities.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

In-built function

-----------------
abs(n)
Module: All functions are presents in built-in functions
Purpose: To find out absolute value of the argument
Arguments:1.n required int
Return: integer

all(iterable)
purpose:To find out all items in the iterable are true or not
If the iterable is empty (), return True.
When used on a dictionary, the all() function checks if all the keys are
true, not the values.
Arguments: 1 iterable optional
Return: booian value

any(iterable)
Purpose:to find out any object in the iterable are true or not
If the iterable is empty(), return False
When used on a dictionary, the any() function checks if any keys are
true, not the values.
Arguments: 1.Iterable optional
Return: bool value

ascii(object)
Purpose: to find out the ascii value of the object
Arguments taking: 1. Object required
Return: ascii converted value

bin(n)
Purpose: To convert value into binary form
Argument taking: 1 n int Required
Return: binary representation of an integer.in string value

bool(object)
Purpose: to convert object into boolian value
Argument taken: 1. Object optional
Return: bool value

bytearray(x, encoding, error)


Purpose: To convert bytearray
Argument taken:
Return: it returns bytearray value

bytes (x, encoding, error)


Purpose:
The difference between bytes() and bytearray() is that bytes() returns
an object that cannot be modified, and bytearray() returns an object that can be
modified.
Argument taken:
Return: bytes value

callable(Object)
Purpose: to check object is callable or not
Argument taken: 1.object required
Return: boolian value

chr(number)
Purpose: returns the character that represents the specified unicode.
Argument taken:1 number required
Return: Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

Compile (source, filename, mode, flag, dont_inherit, optimize)


Purpose:
Argument taken: 1. source required ,2.filename required 3. Mode required, 4
flag optional default 0, 5.dont_inherit optional default False , 6.optimize
optional default -1
Return: code value

complex(real, imaginary)
Purpose: to Create a complex number from a real part and an optional imaginary
part
Argument taken: 1.real required int, 2, imaginary optional int default 0
Return: complex value

delattr(object, attribute)
Purpose: To delete the specified attribute from the specified object.
Argument taken: 1. Object required, 2. Attribute required
Return: NoneType

dict(keywordargumtnts)
Purpose: to create dictionary object
Arguments taken: keyword arguments optional
Return: dict value

dir(object)
purpose: returns all properties and methods of the specified object, without
the values.
Argument taken: 1.object
Return: List

divmod(dividend, divisor)
Purpose: to calculate divided value and remaining value in form of tuple
Argument taken: 1.dividend required, 2.divisor required
Return: tuple

enumerate (iterable, start)


Purpose:
Argument taken: 1.iterable required, 2.start optional default is 0
Return: enumerate

eval(expression, global, local)


Purpose: To Evaluate the given source (expression) in the context of globals
and locals
Argument taken:1.expression str required 2.global optional, 3.local optional
Return: value

exec(object, global, locals)


Purpose: Execute the given source in the context of globals and locals.
Argument taken: 1. Object The object may be a string representing one or more
Python statements
or a code object as returned by compile(),2.global optional,
3. Locals optional

filter(function, iterable)
Purpose: to filter required specified value from function
Argument taken: 1.function or None (Required), 2. Iterable (required)
Return: filter
float(value)
Purpose: Convert a string or number to a floating point number, if possible
Argument taken:1. Value(must be string of real number(optional)default is 0
Return: float value

format (value, format)


Purpose: formats a specified value into a specified format.
Argument taken: 1.value (required) 2. Format format you want to format the
value into.
Legal values:
-------------
'<' - Left aligns the result (within the available space)
'>' - Right aligns the result (within the available space)
'^' - Center aligns the result (within the available space)
'=' - Places the sign to the left most position
'+' - Use a plus sign to indicate if the result is positive or negative
'-' - Use a minus sign for negative values only
' ' - Use a leading space for positive numbers
',' - Use a comma as a thousand separator
'_' - Use a underscore as a thousand separator
'b' - Binary format
'c' - Converts the value into the corresponding unicode character
'd' - Decimal format
'e' - Scientific format, with a lower case e
'E' - Scientific format, with an upper case E
'f' - Fix point number format
'F' - Fix point number format, upper case
'g' - General format
'G' - General format (using a upper case E for scientific notations)
'o' - Octal format
'x' - Hex format, lower case
'X' - Hex format, upper case
'n' - Number format
'%' - Percentage format
Return: string

frozenset(iterable)
Purpose: Build an immutable unordered collection of unique elements.
Argument taking: iterable optional
Return: frozenset object

getattr (object, attribute, message)


purpose:To get the value of the specified attribute from the specified object.

argument taken:1. Object required, 2. Attribute required,3 message optional if


the value does not have in the specified object this message will sown
return: value

globals()
Purpose: To show the dictionary containing the current scope's global
variables.
Argument taken: no any argument
Return: Dictionary

hasattr(object, attribute)
Purpose: the object has an attribute with the given name.
Argument taken:1. Object required, 2.attribute required
Return: bool value
hex()
Purpose:To the hexadecimal representation of an integer.
Argument taken:1.intiger required
Return: string

id(object)
Purpose:to show the identity of an object.
All objects in Python has its own unique id.
The id is assigned to the object when it is created.
The id is the object's memory address, and will be different for each
time you run the program. (except for some object that has a constant unique id,
like integers from -5 to 256)
Argument taken: 1. object required
Return: identity of an object.

input(prompt)
Purpose:to take input from user
Argument taken:1.prompt optional
Return:string

int(value, base)
Purpose: To convert in to integer value
Argument taken: 1.value optional default is 0,2,base optional
Return: integer

isinstance(object,type)
Purpose: To check whether an object is an instance of a class or of a subclass
thereof
Argument taken: 1. Object required, 2. Type required
Return: bool

Issubclass( Object, subclass)


Purpose: To check whether 'cls' is derived from another class or is the same
class.
Argument taken: 1.object required, 2. Subclass required
Return: bool

iter(object, sentinel)
Purpose: Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the
sentinel.
Argument taken: 1.object required, 2. Sentinel optional

len(object)
purpose:To check the number of items in a container.
Argument taken: 1.object required
Return: int

list(iterable)
purpose:To generate list object
Argument taken: 1. Iterable optional
Return: list

locals()
purpose: To check dictionary containing the current scope's local variables.
Argument taken: not taking any argument
Return: dictionary
map(function, iterable)
Purpose: function executes a specified function for each item in an iterable.
The item is sent to the function as a parameter.
Argument taken: 1.function required, 2.iterable required
Return: map

max(iterable)
Purpose: to findout maximum value in iterable
Argument taken: 1.iterable required
Return: value

min(iterable)
purpose: to findout minium value in iterable
Argument taken: 1.iterable required
Return: value

memoryview(object)
Purpose: Create a new memoryview object which references the given object.
Argument taken: 1. byte object or bytearray object required
Return:

next(iterable, default)
Purpose: Return the next item from the iterator. If default is given and the
iterator
is exhausted, it is returned instead of raising StopIteration.
Argument taken: 1.iterable object required, 2.default optional
Return:value

object()
purpose: To create an empty object
you cannot add new properties or methods for this object
Argument taken: no required
Return: object

oct(int)
Purpose : convert a number into octal
Argument required: int number required
Return: string

open()
Purpose: To opens a file, and returns it as a file object.

ord(character)
Purpose: the Unicode code point for a one-character string.
Argument taken: 1.single character stirng required
Return: int

pow(base value, exponent value, for finding modulus value )


Purpose: to calculate exponential value of the base
Argument taken: 1.base value required, 2. Exponent value required, 3.for
finding modulus optional
Return : int

print(object, sep=' ', end='\n', file=None, flush=False)


Purpose: Prints the values to a stream, or to sys.stdout by default.
Argument taken :1.object optional , 2.seprator optional default (space), 3. End
optional default new line, 4.file optional default none, 5.flush optional default
false
Return: NoneType

range(start, stop, step)


Purpose: an object that produces a sequence of integers from start
(inclusive)to stop (exclusive) by step.
Argument taken:1. Start optional default 0, 2,stop required 3.step optional
default is 1
Return: range

reversed(sequence)
Purpose: to make a reverse iterator over the values of the given sequence.
Argument taken: 1.sequence required
Return : reversed object

round(number, digit)
Purpose:to roundup the digits
Arguments taken: 1.number required 2.digits optional default 0
Return: float or intiger

set(iterable)
Purpose: to create set
Argument taken:1.iterable optional
Return: set

setattr(Object, attribute, value)


Purpose: Sets the named attribute on the given object to the specified value
Argument taken: 1.object required, 2.attribute required, 3. Value required
Return: None

slice(start, end, step)


Purpose: to create a slice object
Argument required: 1. Start optional default is 0, 2. End required,3.step
optional default is 1
Return : slice object

sorted(iterable, key=key, reverse=reverse)


You cannot sort a list that contains BOTH string values AND numeric values.
Purpose: To Specify accending or descending order, String are sorted
alphabetically, and numbers are sorted numerically
Arguments taken: 1.Iterable Required (sequence to sort, list dict,tuble etc) 2.
key (optional) a function to execute to decide the order default is None
3. reverse (optional) a boolean , False wil sort ascending,
True will sort descending defalut is False
Return:a new list containing all items from the iterable in ascending order.

You might also like