Avec python il est possible de formater un nombre en string avec python. Pour cela veuillez consulter la documentation complète sur le sujet (voir String Formatting Operations). Quelques exemples:
>>> i = 99>>> type(i)<type 'int'>>>> s = "%05d" % i>>> s'00099'>>> type(s)<type 'str'>
Autre exemple
>>> hour = 14>>> min = 35>>> second = 10>>> s = "%02d:%02d:%02d" % (hour, min, second)>>> s'14:35:10'
Exemple avec un float
>>> x = 4.>>> s = "%e" % x>>> s'4.700000e+00'>>> type(s)<type 'str'>
Recherches associées
| Liens | Site |
|---|---|
| String Formatting Operations | Python Doc |
| Best way to format integer as string with leading zeros? | stackoverflow |
| Format numbers to strings in Python | stackoverflow |
