#!/usr/bin/env python3#-*- coding: utf-8 -*-
a= 'abc'
def capitalize(self): #real signature unknown; restored from __doc__
"""S.capitalize() -> str
#让第一个字母大写"""
return ""a1=a.capitalize()print(a1)#结果#Abc
def center(self, width, fillchar=None): #real signature unknown; restored from __doc__
#width宽度;fillchar=None,填充字符,默认为空格
"""S.center(width[, fillchar]) -> str
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space默认为空格)"""
return ""a2= a.center(10) #让a这个字符串宽度为10.且abc位于中央。
print(a2)#abc
a3 = a.center(10,'@') #以@为填充符。
print(a3)#@@@abc@@@@
def count(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""#统计子序列出现的次数。
#sub附属的,起始位置,结束为止
S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation."""
return0
a4= a.count('a',0,2) #计算从0-2之间有几个a。
print(a4)#1
def encode(self, encoding='utf-8', errors='strict'): #real signature unknown; restored from __doc__
"""#转码,encoding是编码方式;默认转成utf-8。errors是错误处理方式。
S.encode(encoding='utf-8', errors='strict') -> bytes"""
return b"" #返回为b"",就是以b开头。
A = '张洪震'a5= A.encode('gbk',errors='ignore') #转成gbk编码,忽略错误。注:其实内部还是从utf-8转为Unicode,再从Unicode转为gbk。
print(a5)#b'\xd5\xc5\xba\xe9\xd5\xf0'
def endswith(self, suffix, start=None, end=None): #real signature unknown; restored from __doc__
"""S.endswith(suffix[, start[, end]]) -> bool
#suffix后缀,
suffix can also be a tuple of strings to try.#后缀也可以是一个元组。"""
return False #返回正误
a6 = a.endswith('c',0,3) #这里注意一下,是0<=suffix position.<3,#a6 = a.endswith('c',0,2),这样写会报错。
print(a6)#True
def startswith(self, prefix, start=None, end=None): #real signature unknown; restored from __doc__
"""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.
判断是否是以“。。”开头,可以指定开头和结尾的位置,"""
returnFalsedef expandtabs(self, tabsize=8): #real signature unknown; restored from __doc__
"""S.expandtabs(tabsize=8) -> str
Return a copy#副本of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
#返回一个用空格代替tab键的副本。"""
return ""B= 'zhan g'b7=B.expandtabs()print(b7)#zhan g
def find(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""#查找出sub所在的位置。
S.find(sub[, start[, end]]) -> int
Return -1 on failure.#如果失败的话返回-1."""
return0
a8=a.find('c',0,3) #在0-2的位置找c。
a9 =a.index('b') #index和find都是找,index找不到的话会直接报错。
print(a8,a9)#2 1
def format(*args, **kwargs): #known special case of str.format
"""S.format(*args, **kwargs) -> str
Return a formatted version of S, using substitutions from args and kwargs.
返回一个格式化的字符串,用替换的来自于传参。
The substitutions are identified by braces ('{' and '}').
被替换的东西用{}来定义"""
passC='zhen,{0},{1}'a10= C.format('是四个字母','对') #传参为“是四个字母”
print(a10)#zhen,是四个字母,对
D ='zhen,{dd},{ddd}'a10= D.format(dd='是四个字母',ddd='对') #做一个动态对应
print(a10)#zhen,是四个字母,对
#以is开头的大都是判断,举一个例子
def isalnum(self): #判断是否是文字数字
returnFalsedef join(self, iterable): #real signature unknown; restored from __doc__
"""#主要用来做拼接
S.join(iterable) -> str
Return a string which is the concatenation of the strings in the
iterable.
The separator between elements is S.元素之间的分隔符是S.。"""
return ""E=['ni hao','zhang','chi le ma'] #定义一个列表
a11= ",".join(E) #让“E”中的字符串以“,”为分割符相连。
print(a11)#ni hao,zhang,chi le ma
def ljust(self, width, fillchar=None): #real signature unknown; restored from __doc__
"""S.ljust(width[, fillchar]) -> str
左对齐。参数为宽度,填充字段.默认为空"""
return ""
def rjust(self, width, fillchar=None): #real signature unknown; restored from __doc__
"""S.rjust(width[, fillchar]) -> str
右对齐。参数为宽度,填充字段,默认为空"""
return ""F= 'abc'a12=F.ljust(7,'#') #让F的宽度为7个字符,如果不够7个,那么在字符串的右边填充上“#”把字符串“挤”至左对齐。
print(a12)
a13=F.rjust(6,'$') #让F的宽度为6个字符,如果不够6个,那么在字符串的左边填充上“#”把字符串“挤”至右对齐。
print(a13)#结果
'''abc####
$$$abc'''
def lower(self): #real signature unknown; restored from __doc__
"""S.lower() -> str
Return a copy of the string S converted to lowercase.
返回一个字符串的小写副本。"""
return ""
def upper(self): #real signature unknown; restored from __doc__
"""S.upper() -> str
大写
Return a copy of S converted to uppercase."""
return ""
def strip(self, chars=None): #real signature unknown; restored from __doc__
"""S.strip([chars]) -> str
Return a copy of the string S with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
删除开头和结尾空格,如果给定字符或不是空的,那么删除给定字符"""
return ""
def lstrip(self, chars=None): #real signature unknown; restored from __doc__
"""S.lstrip([chars]) -> str
Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
返回一个去掉字符串的开头空格的副本
如果给定字符而不是空的,则删除给定字符。"""
return ""a14=a.lstrip('a')print(a14)def rstrip(self, chars=None): #real signature unknown; restored from __doc__
"""S.rstrip([chars]) -> str
Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
返回一个去掉字符串的结尾空格的副本
如果给定字符而不是空的,则删除给定字符。"""
return ""a15=a.rstrip('c')print(a15)def partition(self, sep): #real signature unknown; restored from __doc__
"""S.partition(sep) -> (head, sep, tail)
Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings.
在字符串中搜索分隔符,并返回它前面的部分、分隔符本身和后面的部分。如果找不到分隔符,返回s和两个空字符串。"""
passa16= a.partition('b') #以b为分隔符
print(a16)#('a', 'b', 'c')
a17= a.partition('d') #以d为分割符
print(a17)#('abc', '', '')
def replace(self, old, new, count=None): #real signature unknown; restored from __doc__
"""S.replace(old, new[, count]) -> str
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced."""
return ""h='aaaaaaa'h1= h.replace('a','b',3) #用b替换a,个数为3
h2=h.replace('a','9',2)print(h1,h2)#bbbaaaa 99aaaaa
def split(self, sep=None, maxsplit=-1): #real signature unknown; restored from __doc__
"""S.split(sep=None, maxsplit=-1) -> list of strings
分割。"""i='zhang hong z hen'i1=i.split('h',2) #指定h为分隔符,i中有3个h,指定最大为2个,所以,只有两个作为分割符了
i2=i.split() #没有指定,则以空格为分割符并删除空格
print(i1,i2)#['z', 'ang ', 'ong z hen'] ['zhang', 'hong', 'z', 'hen']
def swapcase(self): #real signature unknown; restored from __doc__
"""S.swapcase() -> str
Return a copy of S with uppercase characters converted to lowercase
and vice versa.
如果是大写,那么给它换成小写,反之亦然。"""
return ""
def title(self): #real signature unknown; restored from __doc__
"""S.title() -> str
Return a titlecased version of S, i.e. words start with title case
characters, all remaining cased characters have lower case."""
return ""