Functions Flashcards
Chapter 4
Returns the absolute value of a number
X=abs(number)
Returns True if all items in an iterable object are true
x=all(iterable)
Returns True if any item in an iterable object is true
x=any(iterable)
Returns a readable version of an object. Replaces none-ascii characters with escape character
x=ascii(object)
Returns the binary version of a number
X=bin(integer)
Returns the boolean value of the specified object
X=bool(object)
Returns True if the specified object is callable, otherwise False
X=callable(object)
Returns the specified source as an object, ready to be executed
X=compile(source, filename, mode, flag, dont_inherit, optimize)
Returns a complex number
X=complex(real,imaginary)
Deletes the specified attribute (property or method) from the specified object
delattr(object, attribute)
Returns a dictionary (Array)
X=dict(key=value,…)
Returns the quotient and the remainder when argument1 is divided by argument2
X=divmod(dividend, divisor)
Takes a collection (e.g. a tuple) and returns it as an enumerate object
X=enumerate(iterable, start)
Use a filter function to exclude items in an iterable object
X=filter(function, iterable)
Returns a floating point number
X=float(value)
Formats a specified value
X=format(value, format)
Returns the value of the specified attribute (property or method)
X=getattr(object, attribute, default)
Returns True if the specified object has the specified attribute (property/method)
X=hasattr(object, attribute)
Returns the hash value of a specified object
Hash()
Allowing user input
X=input(prompt)
Returns an integer number
X=int(value, base)
Returns True if a specified object is an instance of a specified object
X=isinstance(object, type)
Returns True if a specified class is a subclass of a specified object
X=issubclass(object, subclass)
Returns the length of an object
X=len(object)
Returns a list
X=list(iterable)
Returns the largest item in an iterable
X=max(n1, n2, n3, …)
Or:
X=max(iterable)
Returns the smallest item in an iterable
X=min(n1, n2, n3, …)
Or:
X=min(iterable)
Returns the next item in an iterable
X=next(iterable, default)
Returns a new object
X = object()
Opens a file and returns a file object
open(file, mode)
Modes:
“r” - Read - Default value. Opens a file for reading, error if the file does not exist
“a” - Append - Opens a file for appending, creates the file if it does not exist
“w” - Write - Opens a file for writing, creates the file if it does not exist
“x” - Create - Creates the specified file, returns an error if the file exist
Returns the value of x to the power of y
pow(x, y, z)
Prints to the standard output device
print(object(s))
Returns a sequence of numbers, starting from 0 and increments by 1 (by default)
X=range(start, stop, step)
Returns a reversed iterator
X=reversed(sequence)
Rounds a number
X=round(number, digits)
Returns a new set object
X=set(iterable)
Sets an attribute (property/method) of an object
setattr(object, attribute, value)
Returns a slice object
X=slice(start, end, step)
Returns a sorted list
Note: You cannot sort a list that contains BOTH string values AND numeric values.
sorted(iterable, key=key, reverse=reverse)
Returns a string objec
X=str(object)
Sums the items of an iterator
X=sum(iterable, start)
Returns a tuple
Note: You cannot change or remove items in a tuple.
X=tuple(iterable)
Returns the type of an object
X=type(object, bases, dict)
Returns an iterator, from two or more iterators
Y=zip(iterator1, iterator2, iterator3 …)