用法:
textwrap.indent(text, prefix, predicate=None)
將
prefix
添加到text
中選定行的開頭。通過調用
text.splitlines(True)
分隔行。默認情況下,
prefix
被添加到不完全由空格組成的所有行(包括任何行結尾)。例如:
>>> s = 'hello\n\n \nworld' >>> indent(s, ' ') ' hello\n\n \n world'
可選的
predicate
參數可用於控製縮進的行。例如,很容易將prefix
添加到空行和僅包含空格的行中:>>> print(indent(s, '+ ', lambda line: True)) + hello + + + world
3.3 版中的新函數。
相關用法
- Python textwrap.dedent用法及代碼示例
- Python textwrap.TextWrapper用法及代碼示例
- Python textwrap.shorten用法及代碼示例
- Python tensorflow.eye()用法及代碼示例
- Python tensorflow.fill()用法及代碼示例
- Python tensorflow.math.special.dawsn()用法及代碼示例
- Python tensorflow.ensure_shape()用法及代碼示例
- Python tensorflow.math.special.fresnel_cos()用法及代碼示例
- Python tensorflow.raw_ops.Cos()用法及代碼示例
- Python tensorflow.get_logger()用法及代碼示例
- Python tensorflow.math.sqrt()用法及代碼示例
- Python test.support.catch_unraisable_exception用法及代碼示例
- Python tensorflow.math.atanh()用法及代碼示例
- Python tensorflow.math.xlogy()用法及代碼示例
- Python tensorflow.math.cos()用法及代碼示例
- Python tell()用法及代碼示例
- Python tensorflow.math.nextafter()用法及代碼示例
- Python tensorflow.math.floordiv()用法及代碼示例
- Python tensorflow.DeviceSpec.replace()用法及代碼示例
- Python tensorflow.math.confusion_matrix()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 textwrap.indent。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。