python 学习 笔记 format 用法
来源:互联网 发布:算法的概念简单例题 编辑:程序博客网 时间:2024/04/30 06:19
习惯了用 print ‘%s’ 这种结构来格式化输出, 今天无意中看到python 有format函数,读了一遍它的帮助文档。使用起来还是比较方便的。 摘录出来。
# 基本的按顺序输出 python版本需要2.7以上>>> '{0} {1} {2}'.format('a', 'b', 'c')'a b c'# 输出顺序可以调整>>> '{1} {0} {2}'.format('a', 'b', 'c')'b a c'# 右对其保留位置用其他字符代替空格# * 用星号填充空格# > 右对齐# 30 保留三十位置 >>> '{:*>30}'.format('right aligned test')'************right aligned test'# 字符居中>>> '{:*^36}'.format('fillwithstart')'***********fillwithstart************'# 各种数字进制显示>>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:#b}".format(15)'int: 15; hex: f; oct: 17; bin: 0b1111'
0 0
- python 学习 笔记 format 用法
- python学习笔记8--format
- python学习笔记-format()函数
- 【python学习笔记】format字符串
- python学习笔记(24)--format函数
- Python Format用法
- Python format用法
- python:string.format用法
- python中format用法
- python format用法
- python format 用法详解
- python中format用法
- Python format 笔记
- python format 学习
- python学习:format方法
- [Python学习笔记]3——强大的.format
- Python学习笔记: 增强的格式化字符串format函数
- Python的format方法用法
- ZOJ 3782 Ternary Calculation
- cpp反汇编之const分析
- Square 开源库Flow和Mortar的介绍
- JS基础知识之:几个有启示的地方
- C语言sendto()函数:经socket传送数据
- python 学习 笔记 format 用法
- 毕设论文英文文献下载
- cft0.o
- 根权限gedit打开文件
- vim 配置说明
- 引导加载程序之争:了解 LILO 和 GRUB
- 常用的vi/vim命令
- JE分词器
- 不认识的汉字