2. Built-in Functions
See 1.6 for general information on functions.
float()
float(b)
returnsb
as a float object.b
may be of type str or intint()
int(b)
returnsb
as an integer object.b
may be of type float or str. Ifb
is of type float,int(b)
ignores decimal places. Ifb
is of type str,b
must not have decimal places (convert to float first)len()
len(s)
returns the number of elements in object s. Returns number of characters for str objects, number of elements for list objects, number of sublist for nested list objects, number of key-value pairs for dict objects.max()
max(s)
returns the max value of the iterable (see 1.4.2) objects
.max(a,b, ...)
returns the largest value of the argumentsa, b, ...
min()
min(s)
returns the min value of the iterable (see 1.4.2 objects
.mix(a,b, ...)
returns the smallest value of the argumentsa, b, ...
print() - (See section 9 for more options)
Prints objects to the screen.
range()
range(b)
returns an immutable and iterable sequence of numbers from 0 tob-1
.range(a,b)
returns a sequence of numbers froma
tob-1
. Commonly used in for loops (see 6.1.)sorted()
sorted(s)
returns a new sorted list from the items in the iterable (see 1.4.2 objects
.str()
str(c)
returns a string version of the objectc
.sum()
sum(s)
returns the sum of items in the iterable (see 1.4.2) objects
.type()
type(c)
returns the type of objectc
. Knowing the type (i.e. list, dict, dataframe, etc.) tells you what methods/attributes can be called on that object.