文章目录
- 查
- 返回布尔值
-
- def startswith(self, prefix, start=None, end=None):
- def endswith(self, suffix, start=None, end=None):
- def isalnum(self): 全是字母或数字
- def isalpha(self): 全是字母
- def isdecimal(self): 整数
- def isdigit(self):
- def isidentifier(self):
- def islower(self):
- def isnumeric(self):
- def isprintable(self):
- def isspace(self):
- def istitle(self):
- def isupper(self):
- def __contains__(self, *args, **kwargs): # in 触发
- def __eq__(self, *args, **kwargs): # == 触发
- def __ne__(self, *args, **kwargs):
- def __ge__(self, *args, **kwargs):
- def __gt__(self, *args, **kwargs):
- def __le__(self, *args, **kwargs):
- def __lt__(self, *args, **kwargs):
- 返回数字类型
-
- def count(self, sub, start=None, end=None):
- def find(self, sub, start=None, end=None):
- def index(self, sub, start=None, end=None):
- def rfind(self, sub, start=None, end=None):
- def rindex(self, sub, start=None, end=None):
- def __len__(self, *args, **kwargs):
- def __mod__(self, *args, **kwargs):
- def __rmod__(self, *args, **kwargs):
- def __rmul__(self, *args, **kwargs):
- def __sizeof__(self):
- 字母变大小
- 变化其中的值
- 增加自定义内容
- 删除自定义内容
- 返回列表list类型
- str和bytes转换
- tab键相关
- 返回元组类型
- 返回可迭代对象
str是python的一个内置的一个类,继承object,其使用频率非常多。该类定义了很多方法,常用的方法如下:
源码:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/09f9061834e6f91971e9f28f3f6bbdb8.png)
查
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
<