Inbuilt Functions
Code | Description |
---|---|
abs() |
Returns absolute value abs(5) : 5abs(1.500) : 1.5abs(3+4j) : 5.0 (magnitude) |
all(iterable) |
Returns true if all items in iterable are true (or iterable is empty)all([1, 'hey', [1]]) : Trueall(0), all('') : False |
any(iterable) |
Returns true if any element of iterable is true |
bin(integer) |
Returns binary value of given integer |
chr(i) |
Returns character whose unicode value is 'i'chr(97) : achr(8364) : € |
delattr(object, name) |
deletes the 'name' attribute from object's implementation |
dir() |
"if no argument is passed: returns attributes/names in current scope if argument is passed: returns attribute of object passed calls __dir__() method if defined |
divmod(a, b) |
Returns (a // b, a % b) |
enumerate(iterable, start=0) |
seasons = ['Spring', 'Summer', 'Fall', 'Winter'] list(enumerate(seasons, start=1)) OP: [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')] |
filter(function, iterable) |
Returns an iterator from those elements of iterable for which function returns true. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed. |
getattr(object, name[, default]) |
getattr(x, 'foobar') will return the value of x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised |
hash(object) |
Returns hash value of object, or retruns output of __hash__() if class defined it |
help(object) |
buit-in help system about given object, if no argument is passed then interactive help system starts in the console |
hex(x) |
Convert an integer number to a lowercase hexadecimal string prefixed with “0x”. If x is not a Python int object, it has to define an __index__() method that returns an integer. |
id(object) |
Returns the unique identity of an object |
input(prompt_string) |
to take user input via console, prompt_string will be printed if provided |
isinstance(object, classinfo) |
returns true if object is an instance of classinfo. Classinfo can be a tuple of classes. |
issubclass(class, classinfo) |
Returns true if class is a subclass of classinfo |
map(function, iterable, ...) |
Return an iterator that applies function to every item of iterable, yielding the results.for multiple iterables, it applies them all to the function parallally, the iterator stops when the shortest iterable is exhausted. |
oct(num) |
Convert an integer number to an octal string prefixed with “0o”. |
ord(c) |
Returns unicode point integer of c |
pow(base, exp[, mod]) |
Rerurns (base ^ exp) % mod |
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) |
print function with all default parameters |
round(number[, ndigits]) |
Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. |
sorted(iterable, *, key=None, reverse=False) |
Returns sorted iterable, key is a function and if provided it first maps iterable to that function and then sorts the iterable |
zip(*iterables) |
Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The iterator stops when the shortest input iterable is exhausted. |