python中关于字符串的操作

文章目录


str是python的一个内置的一个类,继承object,其使用频率非常多。该类定义了很多方法,常用的方法如下:
源码:
在这里插入图片描述

def getitem(self, *args, **kwargs): # real signature unknown

    """ Return self[key]. """
    pass
s = 'kdjfds'
print(s[1])  # d

返回布尔值

def startswith(self, prefix, start=None, end=None):

    """
    S.startswith(prefix[, start[, end]]) -> bool

    Return True if S starts with the specified prefix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    prefix can also be a tuple of strings to try.
    """
    return False

def endswith(self, suffix, start=None, end=None):

    """
    S.endswith(suffix[, start[, end]]) -> bool

    Return True if S ends with the specified suffix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    suffix can also be a tuple of strings to try.
    """
    return False

def isalnum(self): 全是字母或数字

    """
    S.isalnum() -> bool

    Return True if all characters in S are alphanumeric
    and there is at least one character in S, False otherwise.
    """
    return False

print('sdfdsfadsf34535原'.isalnum())  # True
print('sdfdsfadsf34535原%$#'.isalnum())  # False

def isalpha(self): 全是字母

    """
    S.isalpha() -> bool

    Return True if all characters in S are alphabetic
    and there is at least one character in S, False otherwise.
    """
    return False

print('sdf原'.isalpha())  # True
print('sd35'.isalpha())  # False

def isdecimal(self): 整数

    """
    S.isdecimal() -> bool

    Return True if there are only decimal characters in S,
    False otherwise.
    """
    return False

print('4.9898'.isdecimal())  # False
print('345234'.isdecimal())  # True

def isdigit(self):

    """
    S.isdigit() -> bool

    Return True if all characters in S are digits
    and there is at least one character in S, False otherwise.
    """
    return False

def isidentifier(self):

    """
    S.isidentifier() -> bool

    Return True if S is a valid identifier according
    to the language definition.

    Use keyword.iskeyword() to test for reserved identifiers
    such as "def" and "class".
    """
    return False

def islower(self):

    """
    S.islower() -> bool

    Return True if all cased characters in S are lowercase and there is
    at least one cased character in S, False otherwise.
    """
    return False

def isnumeric(self):

    """
    S.isnumeric() -> bool

    Return True if there are only numeric characters in S,
    False otherwise.
    """
    return False

def isprintable(self):

    """
    S.isprintable() -> bool

    Return True if all characters in S are considered
    printable in repr() or S is empty, False otherwise.
    """
    return False

def isspace(self):

    """
    S.isspace() -> bool

    Return True if all characters in S are whitespace
    and there is at least one character in S, False otherwise.
    """
    return False

def istitle(self):

    """
    S.istitle() -> bool

    Return True if S is a titlecased string and there is at least one
    character in S, i.e. upper- and titlecase characters may only
    follow uncased characters and lowercase characters only cased ones.
    Return False otherwise.
    """
    return False

def isupper(self):

    """
    S.isupper() -> bool

    Return True if all cased characters in S are uppercase and there is
    at least one cased character in S, False otherwise.
    """
    return False

def contains(self, *args, **kwargs): # in 触发

    """ Return key in self. """
    pass

def eq(self, *args, **kwargs): # == 触发

    """ Return self==value. """
    pass

def ne(self, *args, **kwargs):

    """ Return self!=value. """
    pass
print('ab3' != 'abc')  # True
<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值