autodataming的个人博客分享 http://blog.sciencenet.cn/u/autodataming

博文

python %s 适合于多种类型

已有 1461 次阅读 2018-9-27 12:36 |系统分类:科研笔记

 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



https://blog.sciencenet.cn/blog-950202-1137340.html

上一篇:grep
下一篇:挑选代表性的蛋白构象 求平均结构
收藏 IP: 202.127.19.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-16 17:17

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部