python3字符串方法
阿新 • • 發佈:2017-09-14
ndt rjust new span rst iss color dfs con
>>> str=‘absfgsdf‘ >>> type(str) <class ‘str‘> >>> dir(str) [‘__add__‘, ‘__class__‘, ‘__contains__‘包含, ‘__delattr__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘相等, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘反射用到, ‘__getitem__‘, ‘__getnewargs__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mod__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__rmod__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘capitalize‘, ‘casefold‘, ‘center‘, ‘count‘, ‘encode‘, ‘endswith‘, ‘expandtabs‘, ‘find‘, ‘format‘, ‘format_map‘, ‘index‘, ‘isalnum‘, ‘isalpha‘, ‘isdecimal‘, ‘isdigit‘, ‘isidentifier‘, ‘islower‘, ‘isnumeric‘, ‘isprintable‘, ‘isspace‘, ‘istitle‘, ‘isupper‘, ‘join‘, ‘ljust‘, ‘lower‘, ‘lstrip‘, ‘maketrans‘, ‘partition‘, ‘replace‘, ‘rfind‘, ‘rindex‘, ‘rjust‘, ‘rpartition‘, ‘rsplit‘, ‘rstrip‘, ‘split‘, ‘splitlines‘, ‘startswith‘, ‘strip‘, ‘swapcase‘, ‘title‘, ‘translate‘, ‘upper‘, ‘zfill‘] >>> ‘capitalize‘首字母大寫 ‘casefold‘小寫 ‘center‘居中填充‘count‘計數 ‘encode‘編碼, ‘endswith‘結尾, ‘expandtabs‘擴展tab, ‘find‘找到, ‘format‘格式, ‘format_map‘, ‘index‘索引, ‘***********isalnum‘是號碼, ‘isalpha‘是字母, ‘isdecimal‘是整數, ‘isdigit‘是數字, ‘isidentifier‘是標識符, ‘islower‘全部是小寫, ‘isnumeric‘是數字, ‘isprintable‘是可打印, ‘isspace‘是空格, ‘istitle‘是標題, ‘isupper‘全部是大寫*************, ‘join‘連接, ‘ljust‘左對齊, ‘lower‘小寫, ‘lstrip‘刪除, ‘maketrans‘制造反式, ‘partition‘分割, ‘replace‘取代,(((((右-坐,同上‘rfind‘, ‘rindex‘, ‘rjust‘, ‘rpartition‘, ‘rsplit‘, ‘rstrip‘))))), ‘split‘分離, ‘splitlines‘分離行, ‘startswith‘開頭, ‘strip‘刪除, ‘swapcase‘大小寫轉換, ‘title‘標題, ‘translate‘翻譯, ‘upper‘大寫, ‘zfill‘擴充 >>> ‘asdfsd‘[1] ‘s‘ >>> capitalize(self): >>> s.capitalize() ‘Sdfsgfdg‘ >>> casefold(self): >>> s=‘DFTGFFY‘ >>> s.casefold() ‘dftgffy‘ >>> center(self, width, fillchar=None): >>> s=‘sfsggsd‘ >>> s.center(22) ‘ sfsggsd ‘ >>> count(self, sub, start=None, end=None): >>> s=‘sfsggsd‘ >>> s.count(‘s‘) 3 >>> encode(self, encoding=‘utf-8‘, errors=‘strict‘): >>> name=‘明宣‘ >>> name.encode(‘gbk‘) b‘\xc3\xf7\xd0\xfb‘ >>> utf-8轉gbk endswith(self, suffix, start=None, end=None): >>> s=‘sfsggsd‘ >>> s.endswith("sd") True >>> expandtabs(self, tabsize=8): >>> ss=‘\tasfa‘ >>> ss.expandtabs() ‘ asfa‘ >>> find(self, sub, start=None, end=None): >>> name=‘safadsf‘ >>> name=‘safadsf‘ >>> name.find(‘ds‘) 4 >>> format(self, *args, **kwargs): >>> name=‘saf {0}sd{1}‘ >>> name.format(‘aaa‘,666) ‘saf aaasd666‘ >>> >>> name=‘afdsffs{name}sdf{sdf}‘ >>> name.format(name=‘sssss‘,sdf=66666) ‘afdsffsssssssdf66666‘ >>> format_map(self, mapping): index(self, sub, start=None, end=None): >>> name=‘hghghghghghghghgh‘ >>> name.index(‘hg‘,1,-1) 2 >>> isalnum(self): >>> ‘))(*)*‘.isalnum() False >>> ‘sds‘.isalnum() True >>> isalpha(self): >>> ‘124‘.isalpha() False >>> isdecimal(self): >>> ‘345‘.isdecimal() True >>> isdigit(self): >>> ‘5325.35‘.isdigit() False >>> ‘5645‘.isdigit() True >>> isidentifier(self): >>> ‘12ssd‘.isidentifier() False >>> islower(self): >>> ‘sHJK‘.islower() False >>> isnumeric(self): >>> ‘is‘.isnumeric() False >>> isprintable(self): >>> ‘sfs\n‘.isprintable() False >>> isspace(self): >>> ‘ df‘.isspace() False >>> istitle(self): >>> ‘Jkfjs Jkfa‘.istitle() True >>> isupper(self): >>> ‘JKH‘.isupper() True >>> join(self, iterable): >>> ‘-‘.join([‘s‘,‘sf‘,‘sf‘]) ‘s-sf-sf‘ >>> ljust(self, width, fillchar=None): >>> ‘saf‘.ljust(6) ‘saf ‘ >>> lower(self): >>> ‘LoWeR‘.lower() ‘lower‘ >>> lstrip(self, chars=None): >>> ‘sfa ‘.lstrip(‘ ‘) ‘sfa ‘ >>> maketrans(self, *args, **kwargs): >>> a=‘uiuyiyrfy‘.maketrans(‘bcd‘,‘234‘) >>> a {98: 50, 99: 51, 100: 52} >>> ‘abcdefabcdef‘.translate(a) ‘a234efa234ef‘ >>> partition(self, sep): >>> ‘abcdabcdabcd‘.partition(‘bc‘) (‘a‘, ‘bc‘, ‘dabcdabcd‘) >>> replace(self, old, new, count=None): >>> ‘abcabcabc.‘.replace(‘bc‘,‘777‘) ‘a777a777a777.‘ >>> rfind(self, sub, start=None, end=None): >>> ‘aaaaaa‘.rfind(‘a‘,0,5) 4 >>> rindex(self, sub, start=None, end=None): >>> ‘aaaa‘.rindex(‘a‘) 3 >>> rjust(self, width, fillchar=None): >>> ‘aaa‘.rjust(6) ‘ aaa‘ >>> rpartition(self, sep): >>> ‘aaa‘.rpartition(‘a‘) (‘aa‘, ‘a‘, ‘‘) >>> rsplit(self, sep=None, maxsplit=-1): [‘a‘, ‘sdf‘, ‘sdf‘, ‘sdaf‘] >>> rstrip(self, chars=None): >>> ‘asasasasasasasasa‘.rstrip(‘a‘) ‘asasasasasasasas‘ >>> split(self, sep=None, maxsplit=-1): >>> ‘ss af ggs sf s\n‘.split() [‘ss‘, ‘af‘, ‘ggs‘, ‘sf‘, ‘s‘] >>> splitlines(self, keepends=None): >>> ‘a\n\n\na‘.splitlines() [‘a‘, ‘‘, ‘‘, ‘a‘] >>> startswith(self, prefix, start=None, end=None): >>> ‘abcdef‘.startswith(‘ab‘) True >>> strip(self, chars=None): >>> ‘a1a1a1a1‘.strip(‘a‘) ‘1a1a1a1‘ >>> swapcase(self): >>> ‘aaaAAA‘.swapcase() ‘AAAaaa‘ >>> title(self): >>> ‘aaa aaa aaa‘.title() ‘Aaa Aaa Aaa‘ >>> translate(self, table): >>> a=‘uiuyiyrfy‘.maketrans(‘bcd‘,‘234‘) >>> a {98: 50, 99: 51, 100: 52} >>> ‘abcdefabcdef‘.translate(a) ‘a234efa234ef‘ >>> upper(self): >>> ‘aaaAAAaaa‘.upper() ‘AAAAAAAAA‘ >>> zfill(self, width): >>> ‘aaa‘.zfill(5) ‘00aaa‘ >>>
python3字符串方法