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 143 views
143 views asked May 22, 2024 by avibootz
2 answers 234 views
1 answer 186 views
1 answer 115 views
3 answers 216 views
1 answer 139 views
...