Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> s1 = "AbCdEF123"
>>> s1.lower()
'abcdef123'
>>> s1
'AbCdEF123'
>>> s1.upper()
'ABCDEF123'
>>> s1
'AbCdEF123'
>>> s1.isnumeric()
False
>>> s1.isalpha()
False
>>> s1.title()
'Abcdef123'
>>> s1.swapcase()
'aBcDef123'
>>> s1
'AbCdEF123'
>>> s1 = '1234'
>>> s1.isnumeric()
True
>>> s1.isalpha()
False
>>>
>>> s1 = 'AbcDef'
>>> s1.isnumeric()
False
>>> s1.isalpha()
True
>>>
>>> s1 = 'AbcDef'
>>> s1.islower()
False
>>> s1.isupper()
False
>>> s1 = 'bcef'
>>> s1.islower()
True
>>> s1.isupper()
False
>>>
>>> s1 = 'AREDGD'
>>> s1.islower()
False
>>> s1.isupper()
True
>>>
>>> s1 = 'AREDGD'
>>> s1.endswith("DGD")
True
>>> s1.endswith("DG")
False
>>> s1.startswith("ARE")
True
>>> s1.startswith("AE")
False
>>>
>>> s1.split("G")
['ARED', 'D']
>>> s1 = '1,2,3,4,5,6'
>>> s1.split(",")
['1', '2', '3', '4', '5', '6']
>>> s1.count(",")
5
>>> s1 = 'AREDGD'
>>> s1.count("D")
2
>>> s1 = '1,2,3,4,5,6'
>>> s1.replace(",","$")
'1$2$3$4$5$6'
>>> s1 = '1,2,3,4,5,6'
>>> s1.center(50,"*")
'*******************1,2,3,4,5,6********************'
>>> s1 = " 123 "
>>> s1
' 123 '
>>> s1.strip()
'123'
>>> s1 = "abc%%%123^^^^abc"
>>> s1
'abc%%%123^^^^abc'
>>> s1.strip("abc")
'%%%123^^^^'
>>> s1 = 'ABCdeF'
>>> s1.zfill(20)
'00000000000000ABCdeF'
>>> s1 = '+'
>>> s1
'+'
>>> s1.join(["1","f","c","dd","4","55","993"])
'1+f+c+dd+4+55+993'
>>>
>>>
Python内置类型字符串str使用示例
最新推荐文章于 2024-04-16 14:10:17 发布