3 python replace以及split用法

1 replace用法

a = "<SPK/>一年**九店<NPS/>**<NON/>"
help(a.replace)
Help on built-in function replace:

replace(...)
    S.replace(old, new[, count]) -> string

    Return a copy of string S with all occurrences of substring
    old replaced by new.  If the optional argument count is
    given, only the first count occurrences are replaced.
a = a.replace("<","_")
a = a.replace(">","_")
print a
_SPK/_一年**九店_NPS/_**_NON/_

2 split用法

help(a.split)
Help on built-in function split:

split(...)
    S.split([sep [,maxsplit]]) -> list of strings

    Return a list of the words in the string S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string is a separator and empty strings are removed
    from the result.
b=a.split("_")
print b
['', 'SPK/', '\xe4\xb8\x80\xe5\xb9\xb4**\xe4\xb9\x9d\xe5\xba\x97', 'NPS/', '**', 'NON/', '']
print b[0]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值