1>>> foobar = 3.141592
2>>> print(f'My number is {foobar:.2f} - look at the nice rounding!')
3
4My number is 3.14 - look at the nice rounding!
5
1>>> from decimal import *
2>>> getcontext().prec = 6
3>>> Decimal(1) / Decimal(7)
4Decimal('0.142857')
5>>> getcontext().prec = 28
6>>> Decimal(1) / Decimal(7)
7Decimal('0.1428571428571428571428571429')
8
1# 2.6 python and newer and python 3.x
2# Put desired number of decimal by changing the number inside {:.2f} bellow;
3print(' {:.2f}'.format(71.428571))
471.43
5# 2.6 python and older
6# Put desired number of decimal by changing the number inside '%.2f' bellow;
7print('%.2f'%(71.428571))
871.43