str.strip() 奇怪的行为 [英] str.strip() strange behavior

查看:29
本文介绍了str.strip() 奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<预><代码>>>>t1 = "abcd.org.gz";>>>t1'abcd.org.gz'>>>t1.strip(g")'abcd.org.gz'>>>t1.strip(gz")'abcd.org.'>>>t1.strip(.gz")'abcd.or'

为什么'.org''g'不见了?

解决方案

strip(".gz") 删除任何字符 ., gz 从字符串的开头和结尾.

>>> t1 = "abcd.org.gz"
>>> t1
'abcd.org.gz'
>>> t1.strip("g")
'abcd.org.gz'
>>> t1.strip("gz")
'abcd.org.'
>>> t1.strip(".gz")
'abcd.or'

Why is the 'g' of '.org' gone?

解决方案

strip(".gz") removes any of the characters ., g and z from the beginning and end of the string.

这篇关于str.strip() 奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆