python 格式化字符串(官方文档)
来源:互联网 发布:物流平台软件 编辑:程序博客网 时间:2024/05/02 09:39
A conversion specifier contains two or more characters and has the following components, which must occur in this order:
- The "%" character, which marks the start of the specifier.
- Mapping key (optional), consisting of a parenthesised sequence of characters (for example,
(somename)
). - Conversion flags (optional), which affect the result of some conversion types.
- Minimum field width (optional). If specified as an "*" (asterisk), the actual width is read from the next element of the tuple in values, and the object to convert comes after the minimum field width and optional precision.
- Precision (optional), given as a "." (dot) followed by the precision. If specified as "*" (an asterisk), the actual width is read from the next element of the tuple in values, and the value to convert comes after the precision.
- Length modifier (optional).
- Conversion type.
When the right argument is a dictionary (or other mapping type), then the formats in the string must include a parenthesised mapping key into that dictionary inserted immediately after the "%" character. The mapping key selects the value to be formatted from the mapping. For example:
>>> print '%(language)s has %(#)03d quote types.' % \ {'language': "Python", "#": 2}Python has 002 quote types.
In this case no *
specifiers may occur in a format (since they require a sequential parameter list).
The conversion flag characters are:
A length modifier (h
, l
, or L
) may be present, but is ignored as it is not necessary for Python.
The conversion types are:
Notes:
- (1)
- The alternate form causes a leading zero ("0") to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero.
- (2)
- The alternate form causes a leading
'0x'
or'0X'
(depending on whether the "x" or "X" format was used) to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero. - (3)
- The
%r
conversion was added in Python 2.0. - (4)
- If the object or format provided is a unicode string, the resulting string will also be unicode.
Since Python strings have an explicit length, %s
conversions do not assume that '\0'
is the end of the string.
For safety reasons, floating point precisions are clipped to 50; %f
conversions for numbers whose absolute value is over 1e25 are replaced by %g
conversions.2.9 All other errors raise exceptions.
- python 格式化字符串(官方文档)
- 字符串格式化(python)
- (一)Python字符串格式化
- Python(19):格式化字符串
- python字符串格式化(format)
- python 字符串格式化(format)
- python官方文档(自翻译)
- Python官方文档(入门必备)
- python官方文档
- Python unittest 官方文档
- Python官方文档结构图
- python官方文档网址
- Python3.2官方文档教程---格式化输出
- 格式化输出Python3.2官方文档教程
- Python3.2官方文档翻译--输出格式化
- Python 字符串格式化输出(format/printf)
- Python学习笔记(2)格式化字符串
- Python:字符串格式化输出(format/printf)
- SDL与OpenGL配合使用时,OpenGL的纹理的UV坐标是上下颠倒的
- 【cas】基础模式登录流程详解
- SpringMVC发生异常java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
- CSS ::selection伪类选择器
- 简单的listview控件
- python 格式化字符串(官方文档)
- Binary Tree Paths
- ButterKnife基本使用
- 闪频页面优化
- mark学习
- Android ContentProvider和Uri详解
- HDOJ 1715 大菲波数
- leetcode_c++:链表:Intersection of Two Linked Lists(160)
- 判断是否为素数