字符串中百分号%的使用

  • Post author:
  • Post category:其他



参考链接:Python程序设计

在这里插入图片描述


代码实验展示:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> "字%字"
'字%字'
>>> 
>>> a = "是是是%s是是是"
>>> a
'是是是%s是是是'
>>> b = '字符串'
>>> "是是是%s是是是" % '字符串'
'是是是字符串是是是'
>>> 
>>> a%b
'是是是字符串是是是'
>>> 
>>> type(a%b)
<class 'str'>
>>> 
>>> "是是是%d是是是" % 23
'是是是23是是是'
>>> 
>>> "是是是%8d是是%d是" % (33,77)
'是是是      33是是77是'
>>> 
>>> "是%s是是%s是是%d是" % ("a","b",666)
'是a是是b是是666是'
>>> 
>>> "是是是%f是是是" % 3.1415926
'是是是3.141593是是是'
>>> "是是是%f是是是" % 3.141592699999
'是是是3.141593是是是'
>>> "是是是%f是是是" % 3.141592
'是是是3.141592是是是'
>>> "是是是%f是是是" % 3.14
'是是是3.140000是是是'
>>> "是是是%f是是是" % 3.1415926
'是是是3.141593是是是'
>>> "是是是%.2f是是是" % 3.1415926
'是是是3.14是是是'
>>> "是是是%.1f是是是" % 3.1415926
'是是是3.1是是是'
>>> "是是是%.0f是是是" % 3.1415926
'是是是3是是是'
>>> "是是是%.4f是是是" % 3.1415926
'是是是3.1416是是是'
>>> 
>>> 



版权声明:本文为m0_46653437原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。