Class 12: Python Math Inbuilt Functions 4

hex()

Hex() Python built-in functions, converts an integer to hexadecimal.

>>> hex(16)
‘0x10’

>>> hex(False)
‘0x0’

eval()

This Function takes a string as an argument, which is parsed as an expression.

>>> x=7
>>> eval(‘x+7’)
14

>>> eval(‘x+(x%2)’)
8

exec()

exec() runs Python code dynamically.

>>> exec(‘a=2;b=3;print(a+b)’)
5

>>> exec(input(“Enter your program “))
Enter your program print(2+3)
5

>>> exec(input(“Enter your program “))
Enter your program print(10+20)
30
>>>

max()

A no-brainer, max() returns the item, in a sequence, with the highest value of all.

>>> max(2,3,4)
4

>>> max([3,5,4])
5

>>> max(‘hello’,’Hello’)
‘hello’