In this lecture we will learn about a few more representations of numbers in Python.
Using the function hex() you can convert numbers into a hexadecimal format:
hex(246)
'0xf6'
hex(512)
'0x200'
bin(1234)
'0b10011010010'
bin(128)
'0b10000000'
bin(512)
'0b1000000000'
With two arguments, equivalent to x^y. With three arguments, equivalent to (x^y) % z, but may be more efficient (e.g. for longs).
pow(2,4)
16
Absolute Value
abs(-3)
3
abs(3)
3
Round a number to a given precision in decimal digits (default 0 digits). This always returns a floating point number.
round(3)
3.0
round(3.1415926535,2)
3.14
Python has a built-in math library that is also useful to play around with in case you are ever in need of some mathematical operations. Explore the documentation here!