Built in Functions
Built in Functions
code=’a=5\nb=6\nsum=a+b\nprint(“sum=”,
*callable() - Checks if the Object is Callable; sum)’
returns true if the one being called can be called
codecompile=compile(code, ‘file1’, ‘exec’) print(eval(“x+1”))
exec(codecompile)
*exec() – executing a string or a code
sum = 11
syntax: exec()
code=”a=5\nb=6\nprint(a+b)”
*divmod() - Returns a Tuple of Quotient and
Remainder exec(code)
syntax: divmod(x,y)
x and y – integer/float *filter() – filters a given iterable/sequence using a
x – numerator defined function to test if each element of your
y – denominator iterable is true
syntax: filter(function,iterable)
return value: quotient, remainder
x=int(input(“enter a num:”))
students=[“Matthew”, “Maryrose”,
y=int(input(“enter a num:”)) “Kate”]
dm=divmod(x,y) def late(students):
print(dm) late=[“Matthew”]
if (student in late):
*enumerate() – adds a counter to an return True
iterable/sequence
else:
syntax: enumerate(iterable, start=0)
return False
place=[“Venice”, “Germany”, “Manila”]
filteredStudents=filter(late,
a=enumerate(places) students)
print(list(a)) print(“The late student is: ”)
for late in filteredStudents:
place=[“Venice”, “Germany”, “Manila”] print(late)
a=enumerate(places, start=1)
print(list(a))
*hex() – returns hex string of a number (int) return value – list of results
syntax: syntax:
hex(int)
“0x” map(fxn, seq 1, seq 2)
hex(15) def square (n):
‘0xf’
“””This function squares a *pow() – power – returns x raised to the power of
number””” y
return n*n syntax: pow(x, y)
number=[2, 3, 4, 5, 6] pow(x, y, z)
result=map(square, number) - (xy) ÷ z
print (list(result)) pow(3, 2)
9
*max() – returns the largest element from a pow(3, 2, 2)
sequence
1
syntax: max(sequence)