用法:
textwrap.dedent(text)
從
text
的每一行中刪除任何常見的前導空格。這可用於使triple-quoted 字符串與顯示的左邊對齊,同時仍以縮進形式在源代碼中顯示它們。
請注意,製表符和空格都被視為空格,但它們並不相等:
" hello"
和"\thello"
行被認為沒有共同的前導空格。僅包含空格的行在輸入中被忽略,並在輸出中標準化為單個換行符。
例如:
def test(): # end first line with \ to avoid the empty line! s = '''\ hello world ''' print(repr(s)) # prints ' hello\n world\n ' print(repr(dedent(s))) # prints 'hello\n world\n'
相關用法
- Python textwrap.indent用法及代碼示例
- 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.dedent。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。