Help on built-in function format in module __builtin__:
format(...)
format(value[, format_spec]) -> string
Returns value.__format__(format_spec)
format_spec defaults to ""
format(value[, format_spec])
Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument, however there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language.
Note format(value, format_spec) merely calls value.__format__(format_spec).
中文说明:
格式化字符串
通过位置
>>> '{0},{1}'.format('kzc',18)
'kzc,18'
>>> '{1},{0}'.format('kzc',18)
'18,kzc'
>>> '{},{}'.format('kzc',18)
'kzc,18'
>>> '{0},{1},{1}'.format('kzc',18)
'kzc,18,18'
通过关键字参数
>>> '{name},{age}'.format(age=18,name='kzc')
'kzc,18'
通过对象属性