|
python %s 适合于多种类型 数字 字符串 列表 等
>>> a = 1 >>> b = 1.1 >>> c = 'hello' >>> print 'Integer: %s; Float: %s; String: %s' % (a, b, c) Integer: 1; Float: 1.1; String: hello
https://stackoverflow.com/questions/14506430/string-formatting-in-python-can-i-use-s-for-all-types
>>> a=[1,2,3,4]
>>> print "%s test"%a
[1, 2, 3, 4] test
using %s
automatically calls str
on the variable. Since everything has __str__
defined, you should be able to do this without a problem
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 07:49
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社