numeric and scalar types Flashcards
float 64 bit
1 - sign, 11-exponent, 52-fraction
get float info
sys.float_info
decimal context
decimal.getcontext()
set precision on decimals
decimal.getcontext().prec = 6
infinity decimal
decimal.Decimal(“Infinity”)
-7//3
3
import fractions
from fractions import Fraction
create complex number
a=3+2j a=complex(‘(3+2j)’) a=complex(3,2)
extract real from complex
a.real
extract image from complex
a.imag
get a conjugate
a.conjugate()
module for complex
cmath
get polar
modulus, phase = cmath.polar(1+1j)
get phase of complex
cmath.phase()
built-in function that gives distance from zero
abs()
built-in function that perfoms decimal rounding
round(0.2825,3)
convert to 16 base string
hex(52)
convert to 8 base string
oct()
date from timestamp
datetime.date.fromtimestamp(100000)
get weekday (0,1,2,3,4,5,6) from date
d.weekday()
year month and day from date
d.year d.month d.day
get weekday(1,2,3,4,5,6,7)
d.isoweekday()
combine date and time to datetime
datetime.datetime.combine(d, t)