程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python number to string (%)

編輯:Python
  • Global function str
>>> str(123)
'123'
>>> str(1.23)
'1.23'
  • %d
>>> 'a month has %d days'%30
'a month has 30 days'
>>> 'a big month has %d days,a small month has %d days'%(31,30)
'a big month has 31 days,a small month has 30 days'
>>> 'a big month has %10d days'%30
'a big month has 30 days'

notes : use % The latter replaces the former %d
notes :%d In the middle of the 10 The description length is 10,has There is already a space behind it .

  • %f
>>> 'the number is %.1f'%1.23
'the number is 1.2'
>>> 'the number is %10.1f'%1.23
'the number is 1.2'

Be careful :is There is already a space behind it .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved