How to use the getcontext() function to get the default context in Python

1 Answer

0 votes
from decimal import getcontext, Decimal

context = getcontext()
print(context)

dec = Decimal('1.17')
print(dec)

result = dec**5 
print(result)

context.prec = 3 
result = dec**5 
print(result)




'''
run:

Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow])
1.17
2.1924480357
2.19

'''

 



answered Jul 10, 2023 by avibootz

Related questions

1 answer 153 views
153 views asked May 22, 2024 by avibootz
2 answers 240 views
1 answer 197 views
1 answer 124 views
3 answers 225 views
1 answer 144 views
...