方法strip将字符串开头和末尾的空白(但不包括中间的空白)删除,并返回删除后的结果。
>>> ' internal whitespace is kept '.strip()
'internal whitespace is kept'
与lower一样,需要将输入与存储的值进行比较时,strip很有用。回到前面介绍lower时使用 的用户名示例,并假定用户输入用户名时不小心在末尾加上了一个空格。
>>> names = ['gumby', 'smith', 'jones']
>>> name = 'gumby '
>>> if name in names: print('Found it!')
...
>>> if name.strip() in names: print('Found it!')
... Found it!
>>> 你还可在一个字符串参数中指定要删除哪些字符。
>>> '*** SPAM * for * everyone!!! ***'.strip(' *!')
'SPAM * for * everyone'
这个方法只删除开头或末尾的指定字符,因此中间的星号未被删除。
三个资料Q群下载不了也转发不了,先放这里Fine_tuning.zipLangChain.zipdata_clear.rar