- 用法:- str.strip([chars])
- 返回刪除了前導和尾隨字符的字符串的副本。 - chars參數是一個字符串,指定要刪除的字符集。如果省略或- None,則- chars參數默認為刪除空格。- chars參數不是前綴或後綴;相反,它的值的所有組合都被剝離:- >>> ' spacious '.strip() 'spacious' >>> 'www.example.com'.strip('cmowz.') 'example'- 最外層的前導和尾隨 - chars參數值將從字符串中刪除。字符從前端刪除,直到到達- chars中的字符集中不包含的字符串字符。類似的動作發生在尾端。例如:- >>> comment_string = '#....... Section 3.2.1 Issue #32 .......' >>> comment_string.strip('.#! ') 'Section 3.2.1 Issue #32'
相關用法
- Python str.splitlines用法及代碼示例
- Python str.split用法及代碼示例
- Python str.isidentifier用法及代碼示例
- Python str.expandtabs用法及代碼示例
- Python str.isupper用法及代碼示例
- Python str.title用法及代碼示例
- Python str.rstrip用法及代碼示例
- Python str.lstrip用法及代碼示例
- Python str.removeprefix用法及代碼示例
- Python str.zfill用法及代碼示例
- Python str.format_map用法及代碼示例
- Python str.removesuffix用法及代碼示例
- Python str() vs repr()用法及代碼示例
- Python string轉integer用法及代碼示例
- Python string strip()用法及代碼示例
- Python string.octdigits用法及代碼示例
- Python string.whitespace用法及代碼示例
- Python strip()用法及代碼示例
- Python str()用法及代碼示例
- Python string capitalize()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 str.strip。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
