Built-in Functions

abs(x)

x is an integer.


In [57]:
abs(3)


Out[57]:
3

all(iterable)

takes an iteratable and return true if each element is true. It simple join all elements of an iterable with an and operator. Remember zero and empty string are treated as False in python 3.


In [19]:
#def all(iterable):
#    for element in iterable:
#        if not element:
#            return False
#    return True
x = [1,2,0]
print(all(x))
y = [1,2,3,4]
print(all(y))


False
True

any(iterable)

Similar to all(iterable) but use or operator.


In [20]:
#def any(iterable):
#    for element in iterable:
#        if element:
#            return True
#    return False
print(any([0]))
print(any([1,2,3]))
print(any(['']))
print(any([' '])) #Rememebr: space is not equivilant to empty string


False
True
False
True

bin(x)

return a string of binary representation of x (x in any radix.)


In [35]:
print(bin(7))
type(bin(7))


0b111
Out[35]:
str

int(x, base)

Convert a number of string x of base base to an integer in base 10


In [49]:
int(3.4)
int('3')
int("10", 10)


Out[49]:
10

ord(c)

return integer of given unicode c


In [53]:
ord('W')


Out[53]:
87

pow(x, y [, z])

return x^y, if z is given return x^y mod z


In [56]:
pow(3,4)
pow()


Out[56]:
1

In [ ]: