Python3 格式化字符串
2020-02-02 18:21
316 查看
## >>> 'hi %s,your score is %d.' %('vale',98) 'hi vale,your score is 98.'
%s表示用字符串替换,
%d表示用整数替换,有几个
%?占位符,后面就跟几个变量或者值,顺序要对应好。如果只有一个
%?,括号可以省略。
占位符 | 替换内容 |
---|---|
%d | 整数 |
%f | 浮点数 |
%s | 字符串 |
%x | 十六进制整数 |
或者使用format()方法
## >>> 'hello,{0},成绩提升了{1:.1f}%'.format('valecalida',17.123) 'hello,valecalida,成绩提升了17.1%'
转载于:https://my.oschina.net/u/3875850/blog/3021828
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python中字符串的格式化方法小结
- Python—补充_print的用法与字符串的格式化
- Python-字符串格式化符号
- 学习Python的第二天-------字符串格式化
- Python格式化字符串
- Python中format_map与format字符串格式化的区别
- Python之格式化字符串
- Python补充05 字符串格式化 (%操作符)
- python字符串格式化方法 format函数的使用
- python基本数据类型(三)-字符串拼接-格式化输出-深浅复制-python3笔记
- Python补充05 字符串格式化 (%操作符)
- python字符串格式化-format
- python2与python3的print及字符串格式化小结
- 自学Python3.3-字符串格式化 作用域 递归
- Python入门(二)——IDE选择PyCharm,输入和输出,基础规范,数据类型和变量,常量,字符串和编码,格式化
- python3字符串格式化format()函数的简单用法
- Python字符串格式化
- 零基础学python-7.7 字符串格式化方法(1)
- Python之time模块的时间戳、时间字符串格式化与转换(13位时间戳)
- Python中用format函数格式化字符串