python之字符串

接字符串的切片

字符串的判断子串

判断字符 | 字符串是否属于字符串,用 字符/字符串 in 字符串

In [5]: a = 'hello world'

In [6]: 'a' in a    ##判断字符a是否属于字符串a
Out[6]: False

In [7]: 'ello' in a ##判断字符串ello是否属于字符串a
Out[7]: True

In [8]: 'elo' in a
Out[8]: False

In [9]: 'w' in a
Out[9]: True

字符串的重复、连接以及计算长度

重复:字符串*(n) ##n为重复的次数
连接:字符串+字符串
计算长度:len(字符串)

In [1]: print 'hello '*10
hello hello hello hello hello hello hello hello hello hello 

In [2]: print 'hello'+'world'
helloworld

In [3]: a = 'hello westos@@'

In [4]: len(a)
Out[4]: 14

字符串常用操作

字符串的操作有:

In [5]: a
Out[5]: 'hello westos@@'

In [6]: a.
a.capitalize  a.format      a.isupper     a.rindex      a.strip
a.center      a.index       a.join        a.rjust       a.swapcase
a.count       a.isalnum     a.ljust       a.rpartition  a.title
a.decode      a.isalpha     a.lower       a.rsplit      a.translate
a.encode      a.isdigit     a.lstrip      a.rstrip      a.upper
a.endswith    a.islower     a.partition   a.split       a.zfill
a.expandtabs  a.isspace     a.replace     a.splitlines  
a.find        a.istitle     a.rfind       a.startswith  

可以使用help()查看字符串的帮助

In [6]: help(a.format)      ##查看帮助

Help on built-in function format:   ##帮助

format(...)
    S.format(*args, **kwargs) -> string

    Return a formatted version of S, using substitutions from args and kwargs.
    The substitutions are identified by braces ('{' and '}').
(END)

常用:

a.isalnum           ##判断是否是字母或数字
a.isalpha           ##判断是否是字母
a.isdigit           ##判断是否是数字
a.islower           ##判断是否是小写字母
a.isupper           ##判断是否是大写字母
a.isspace           ##判断是否是英文空格
a.istitle           ##判断是否是标题(开头字母为大小写)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值