Δημοσιεύτηκε: 03 Αύγ 2009, 01:32
από sokoban4ever
@Luke
Επειδή η format μορφοποιεί string και όχι ένα πραγματικό αριθμό , με το .3 κλπ μετράει το πλήθος των χαρακτήρων μαζί με την τελεία ;)
http://docs.python.org/3.1/library/stdt ... str.format
έγραψε:Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument.

κάθε πεδίο αντικατάστασης --> { } περιέχει την τιμή (δλδ θέση ) ένος όρισματος
και αφού είναι string ισχύει δηλαδή:
έγραψε:For non-number types the field indicates the maximum field size - in other words, how many characters will be used from the field content. The precision is not allowed for integer values.

από εδώ
http://docs.python.org/3.1/library/stri ... i-language
για παράδειγμα :

Κώδικας: Επιλογή όλων

>>> x='13.3333390'
>>> '{0:.0}'.format(x)
''
>>> '{0:.1}'.format(x)
'1'
>>> '{0:.2}'.format(x)
'13'
>>> '{0:.3}'.format(x)
'13.'
>>> '{0:.4}'.format(x)
'13.3'
>>> '{0:.5}'.format(x)
'13.33'
>>> '{0:.6}'.format(x)
'13.333'
>>> '{0:.7}'.format(x)
'13.3333'
>>> '{0:.8}'.format(x)
'13.33333'
>>>


Ελπίζω να βοήθησα :)
Spoiler: show
Use the Source, Luke :lol: :thumbup: Φιλικά :D