所谓内置方法,就是凡是字符串都能用的方法,这个方法在创建字符串的类中,下面是总结:
首先,我们要学习一个获取帮助的内置函数 help(对象) ,对象可以是一个我们创建出来的,也可以是创建对象的那个类,类也是一个对象,被称为类对象。
当我们进入解释器的交互模式中输入以下代码时:
help(str)
其中,str就是创建字符串的类,然后我们就会得到一长串的结果:
Help on class str in module __builtin__: class str(basestring)
| str(object='') -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.
|
| Method resolution order:
| str
| basestring
| object
|
| Methods defined here:
|
| __add__(...)
| x.__add__(y) <==> x+y #字符串拼接,看+号就知道
|
| __contains__(...)
| x.__contains__(y) <==> y in x #判断x里字符是否在y里
|
| __eq__(...)
| x.__eq__(y) <==> x==y
|
| __format__(...)
| S.__format__(format_spec) -> string
|
| Return a formatted version of S as described by format_spec.
|
| __ge__(...)
| x.__ge__(y) <==> x>=y
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name #获取属性
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y] #索引取值,详情参考python中的序列
|
| __getnewargs__(...)
|
| __getslice__(...)
| x.__getslice__(i, j) <==> x[i:j] #切片,也是序列的一种方法
|
| Use of negative indices is not supported.
|
| __gt__(...)
| x.__gt__(y) <==> x>y
|
| __hash__(...)
| x.__hash__() <==> hash(x)
|
| __le__(...)
| x.__le__(y) <==> x<=y
|
| __len__(...)
| x.__len__() <==> len(x)
|
| __lt__(...)
| x.__lt__(y) <==> x<y
|
| __mod__(...)
| x.__mod__(y) <==> x%y
|
| __mul__(...)
| x.__mul__(n) <==> x*n
|
| __ne__(...)
| x.__ne__(y) <==> x!=y
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| __rmod__(...)
| x.__rmod__(y) <==> y%x
|
| __rmul__(...)
| x.__rmul__(n) <==> n*x
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes #用字节表示在内存中的大小
|
| __str__(...)
| x.__str__() <==> str(x)
|
| capitalize(...)
| S.capitalize() -> string
| '''返回首字母大写字符串副本,对中文无效'''
| Return a copy of the string S with only its first character
| capitalized.
|
| center(...)
| S.center(width[, fillchar]) -> string
| '''返回指定宽度(width)的字符串副本,原字符串居中对齐,可指定用什么来填充多余部分(fillchar)默认为空格,关于对齐和填充可以看上篇博文的解释'''
| Return S centered in a string of length width. Padding is
| done using the specified fill character (default is a space)
|
| count(...)
| 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.
|
| decode(...)
| S.decode([encoding[,errors]]) -> object
| '''解码,将字符串解码成某种字符集'''
| Decodes S using the codec registered for encoding. encoding defaults
| to the default encoding. errors may be given to set a different error
| handling scheme. Default is 'strict' meaning that encoding errors raise
| a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
| as well as any other name registered with codecs.register_error that is
| able to handle UnicodeDecodeErrors.
|
| encode(...)
| S.encode([encoding[,errors]]) -> object
| '''编码,将字符串编码'''
| Encodes S using the codec registered for encoding. encoding defaults
| to the default encoding. errors may be given to set a different error
| handling scheme. Default is 'strict' meaning that encoding errors raise
| a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that is able to handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
| '''判断字符串在某范围内(范围用索引指定,不指定默认是整个字符串)是否以指定的字符串(suffix)结尾,返回布尔值'''
| 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.
|
| expandtabs(...)
| S.expandtabs([tabsize]) -> string
| '''将字符串里的制表符(一般用tab建输入,也可以手动使用特殊字符 \t )转换成空格,默认一个制表符转换成8个空格,也可以指定个数(tabsize),并返回一个转换后的副本'''
| 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.
|
| find(...)
| S.find(sub [,start [,end]]) -> int
| '''在原字符串一定范围内,寻找给定的字符串,找到了返回第一个被找到的字符的索引值,没找到就返回-1'''
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> string
| '''字符串格式化(比%s更为高级,需要的话自行去了解),(*args, **kwargs)是处理函数传参的一种方式,以后继续讲'''
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub [,start [,end]]) -> int
| '''和S.find()作用一样,只不过没找到时会报错'''
| Like S.find() but raise ValueError when the substring is not found.
|
| isalnum(...)
| S.isalnum() -> bool
| '''判断字符串内是否由字母和数字组成,返回布尔值'''
| Return True if all characters in S are alphanumeric
| and there is at least one character in S, False otherwise.
|
| isalpha(...)
| S.isalpha() -> bool
| '''判断字符串是否全是由字母组成,返回布尔值'''
| Return True if all characters in S are alphabetic
| and there is at least one character in S, False otherwise.
|
| isdigit(...)
| S.isdigit() -> bool
| '''判断字符串是否全是由数字组成,返回布尔值'''
| Return True if all characters in S are digits
| and there is at least one character in S, False otherwise.
|
| islower(...)
| 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.
|
| isspace(...)
| S.isspace() -> bool
| '''判断字符串是否都是由空白字符组成(空格),当然,前提是字符串里面最少有一个空格,返回布尔值'''
| Return True if all characters in S are whitespace
| and there is at least one character in S, False otherwise.
|
| istitle(...)
| S.istitle() -> bool
| '''判断字符串是否是标题,而标题的标准就是所有单词的首字母都是大写,其他的都是小写,返回布尔值'''
| Return True if S is a titlecased string and there is at least one
| character in S, i.e. uppercase characters may only follow uncased
| characters and lowercase characters only cased ones. Return False
| otherwise.
|
| isupper(...)
| 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.
|
| join(...)
| S.join(iterable) -> string
| '''字符串的拼接,详情看我前面的博文'''
| Return a string which is the concatenation of the strings in the
| iterable. The separator between elements is S.
|
| ljust(...)
| S.ljust(width[, fillchar]) -> string
| '''左对齐,关于对齐和填充可以看我上篇博文'''
| Return S left-justified in a string of length width. Padding is
| done using the specified fill character (default is a space).
|
| lower(...)
| S.lower() -> string
| '''返回一个全是小写的字符串副本'''
| Return a copy of the string S converted to lowercase.
|
| lstrip(...)
| S.lstrip([chars]) -> string or unicode
| '''和strip类似,不过只去除左边的空格,可以指定字符'''
| Return a copy of the string S with leading whitespace removed.
| If chars is given and not None, remove characters in chars instead.
| If chars is unicode, S will be converted to unicode before stripping
|
| partition(...)
| S.partition(sep) -> (head, sep, tail)
| '''和 split 的分隔类似,但返回的是元祖,不过 split 不过保留给定字符,translate 则会保留,并放在中间,没找到则前后为空'''
| 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.
|
| replace(...)
| S.replace(old, new[, count]) -> string
| '''替换,用新的字符串(new),替换原字符串里有的老字符串(old),用 count 指定替换的次数,不指定则全部替换'''
| Return a copy of string S with all occurrences of substring
| old replaced by new. If the optional argument count is
| given, only the first count occurrences are replaced.
|
| rfind(...)
| S.rfind(sub [,start [,end]]) -> int
| '''和S.find()作用类似,不过寻找方向是从右向左'''
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub [,start [,end]]) -> int
| '''和S.index()作用类似,不过寻找方向是从右向左'''
| Like S.rfind() but raise ValueError when the substring is not found.
|
| rjust(...)
| S.rjust(width[, fillchar]) -> string
| '''右对齐'''
| Return S right-justified in a string of length width. Padding is
| done using the specified fill character (default is a space)
|
| rpartition(...)
| S.rpartition(sep) -> (head, sep, tail)
| '''partition 的右边操作版本'''
| Search for the separator sep in S, starting at the end of S, and return
| the part before it, the separator itself, and the part after it. If the
| separator is not found, return two empty strings and S.
|
| rsplit(...)
| S.rsplit([sep [,maxsplit]]) -> list of strings
| '''split 的右边操作版,要设置了 maxsplit 才能体现,否则都是全部分隔'''
| Return a list of the words in the string S, using sep as the
| delimiter string, starting at the end of the string and working
| to the front. If maxsplit is given, at most maxsplit splits are
| done. If sep is not specified or is None, any whitespace string
| is a separator.
|
| rstrip(...)
| S.rstrip([chars]) -> string or unicode
| '''和strip类似,不过只去除右边的空格,可以指定字符'''
| Return a copy of the string S with trailing whitespace removed.
| If chars is given and not None, remove characters in chars instead.
| If chars is unicode, S will be converted to unicode before stripping
|
| split(...)
| S.split([sep [,maxsplit]]) -> list of strings
| '''按照给定的字符进行分割(从左边开始,找到的第一个),返回一个分割由后剩下的字符串组成的列表(不保留sep),
| maxsplit 指定最大分割次数,否则凡是出现指定的分隔符都会分隔'''
| Return a list of the words in the string S, using sep as the
| delimiter string. If maxsplit is given, at most maxsplit
| splits are done. If sep is not specified or is None, any
| whitespace string is a separator and empty strings are removed
| from the result.
|
| splitlines(...)
| S.splitlines(keepends=False) -> list of strings
| '''根据换行符分割'''
| Return a list of the lines in S, breaking at line boundaries.
| Line breaks are not included in the resulting list unless keepends
| is given and true.
|
| startswith(...)
| 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.
|
| strip(...)
| S.strip([chars]) -> string or unicode
| '''与 center 的填充相反,这里是移除两边的填充,同样也可以指定移除填充的字符,默认是空格,和 center 类似'''
| 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.
| If chars is unicode, S will be converted to unicode before stripping
|
| swapcase(...)
| S.swapcase() -> string
| '''返回一个翻转原字符串字母大小写后的副本'''
| Return a copy of the string S with uppercase characters
| converted to lowercase and vice versa.
|
| title(...)
| S.title() -> string
| '''将字符串转换为标题格式'''
| Return a titlecased version of S, i.e. words start with uppercase
| characters, all remaining cased characters have lowercase.
|
| translate(...)
| S.translate(table [,deletechars]) -> string
| '''根据参数table给出的表(翻译表,翻译表是通过maketrans方法转换而来)转换字符串的字符, 要过滤掉的字符放到 del 参数中'''
| Return a copy of the string S, where all characters occurring
| in the optional argument deletechars are removed, and the
| remaining characters have been mapped through the given
| translation table, which must be a string of length 256 or None.
| If the table argument is None, no translation is applied and
| the operation simply removes the characters in deletechars.
|
| upper(...)
| S.upper() -> string
| '''将字符串的字母全部大写'''
| Return a copy of the string S converted to uppercase.
|
| zfill(...)
| S.zfill(width) -> string
| '''返回一个给定长度的字符串(小于原字符串无效),原字符右对齐,前面用0填充'''
| Pad a numeric string S with zeros on the left, to fill a field
| of the specified width. The string S is never truncated.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __new__ = <built-in method __new__ of type object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
字符串内置方法
首先,我们要注意一个问题,所以的方法都没有改变原字符串本身,都是返回了一个新对象,具体原理我会在讲到函数中说明,而一个新的对象没有把它赋值给一个变量的话,其引用数就为0,在python进行垃圾回收的时候,就会将其从内存中清除。
另外,如果你英文够好的话,其实使用 help() 函数就能够自行学习了,所以这里对帮助函数是一些要点进行说明:
1. <==> 表示相对于,意思这前后的方法效果是一样的
2. -> 表示函数的返回值,意思是这个方法处理以后,返回的值是什么类型,可以是字符串 string ,也可以是数字 int 等等。关于返回值的详细,会在讲函数的时候分析。
3.函数进行传值的时候,对传入的值的类型是有要求的,不然会有很多报错,但这里并没有明说一定要传什么类型的值,而已在英文说明中隐含,所以需要一定的英语阅读能力,英文不好就用经验来堆吧。
首先,我先来说说对于字符串来说,各运算符的含义:
1.+
代表字符串拼接,不多讲了
2.in
表示给定的字符串是否在原字符串里面,返回布尔值
3.==
判断两个字符串是否一样,值相等就行,返回布尔值
4.is
判断是否是统一对象,不仅值要相同,在内存中的地址也有一样,返回布尔值
5.!=
不等于,值和对象都不相等,返回布尔值
5.<,>,<=,>=
字符串的大小判断非常奇特,它是用每个字符逐一比较,比较的是字符对应的ascll编码,例如:
a = 'a' #以十进制的ascll为例,其为97
b = 'b' #以十进制的ascll为例,其为98
a < b
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiwAAABpCAIAAACWH+9IAAAJdElEQVR4nO3daXLkNgyGYd06d5pLKj+SkdUUAX7grvb7VCrV1nABSYmwevNxAgCwyLE6AADA70USqnQcTB2wi+j1ePw1KB7ojvO2HnWrMm4txZCi8WfLhIYg9rJh8FYvz+P3H/3Y9BMg20u2enIwO0v6QVF1xQqhOLPFnKmr7qi99+7Vz9zpbbWptPYsfG/NOZ2e5fueJ+LCrVoOv0DLVPzMtd5c9pyojkDppTg7eiTZqYyeT6Ep2if4+6VVjES8wv02/ZLW2MWSxYMVerWjdxQqqUyduHAjeu9e/RR+PdKbshq593Lvrj34UDzKwq1djr6b5E/JaBzZAmuTUJdidZuCUmaT4KPLGr0kKnqv2E1C7VQYtMX4HekllY1jqySUbSpaXUxCdcFcP/pJKNp+hQlJKNvUvkno+Ov+OJGtksSRLKpVsst45ieh5zxUn7h9g7eOOGtU3Muq190q6Zx11hlSPOhXL3LC06dO7Kii7v1SysaZ/bFlQkK9+10oa6dU1MeuB3PNj3OKRtt/nj8VIRUvGeugEqF4sBiSdUQ86z7SgzLgbKD3iv7UZEsWQmybVrFYy+nrNLJP8PoaFX/0VzO07tkz1RlOcfh1F6RfveOV3xKnOMzQ+alrmWRrM6o757MnVahBq837/+//FN2ynoXFWSpW73IqVi+HftaJkfxf0q9grYoSXK/5KpbpUnJEEtoq+OhyVF8S149O4vGr+2ejcrD4T0qVZLNzRtSo1w5VbK065i6JrePVcS3EhCT0LFDRReNe13dTzZas3kOs6l+ShKqXvKJk4yXxPL5b8DOT0LPAtCRUd0H61RtPGL0jpXCxet8JifYuttPr6tg5CUVrVV9x05ZjTRL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STkHEnuirgZAgCEdEtCAABE1Seh5PUhpwoAAFn3L6U232tQfMNCtjoAAD6SBgBgGZIQAGCZIUmIv/cDAFCQhAAAywz5y6okIQCA4idVdMxDJCEAgOIjVfTKQyQhAIAiTRVd8hBJCACgaEo5Vh4iCQEAFNwJAQCW4TUhAMAyvDsOALAMnxMCACzDNyYAAJYhCQEAlvkX8P46aogYVKIAAAAASUVORK5CYII=" alt="" />
另外,其是每个字符逐一比较的,一旦某个字符比另一个大,则整个字符串都大于另一个,例如
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAi8AAABxCAIAAACSrdS9AAAJ9UlEQVR4nO3da5KbOhCGYXZ99pRNcv4kDJbUra91Bc/7VCrlIbq0BKgHG5PjBABgt2N3AAAAkI1aHQdTBzxF9Hw8/pkUDxoc523HtO2eeTtVDCkaf7FMaAhiLw8M3uol337/0Y9NPwCKvRSrJxuLs6RvFDVXbBCKs1jMmbrmjvp7H179LB3eVptKa3nhe2vO4ZSXH3uciDtu1+7wC/RPxcek6+0WD47OUPxeqtOkR1Kc0+iBFZqi5wRf3N1WJOKp7rfpl7TGLpasbmwwqh29o1BJZerEHTej9+HVT+H3JL0pq5F7L/fu+oMPxaPsuL27Y+wimZf/hmw0pFjb6qCUeUjw0d0aPTcaem9YVkLtNJi01vgd6SWVE/ZR2ajYVLS6mI3agrl+9LNRtP0GC7JRsaknZKO/k28FdPxzf50oVkn6SPauVXLIwNZno3wemo/gscFbW5x9VF3Umve7VdI56qwjpLrRr17lhKdPndhRQ937qVSMs/hjz4SEeve7UPadUlEfux7MNT/OIRptPz9+GkKqnjLWRiVCcWM1JGuLftQdSTYSR16M+F7Rn6NiSSXQgSUbdoNTsjozbc2Giil19X1U/dHfm6H9XjxkneFUh992ZvrVBy4BPXGKwwwdn7qeSbZWpbZjvnhQhRq02rz/ff+n6JKVFxZnqVp9yKHYvDv0o06MJClcmWVr9yhRjpq4apkhJWdko0cFH90dzefG9aOTgfzq/tGobKz+k1IlWfWcEX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oAmGTik4HO21eO1GgGPYkVAPAuj3tqavWB3w1tAgAebu610Rm8PFKujfTCAIC3mPu50ZUwRn0mRDYCgK/0lKemNlw8kY0A4GvM/b6R+B8XhT5V4i4GAPg+rOkAgP3IRgCA/chGAID9yEYAgP2uO7A//gAAsNJPNkr+BgBgmY/MQx4CAGzhZaPrXbv8RfL6PHmXDwDQrnJtlCeYJAM5GwEAENWzkbMluU7i8ggA0GZYNgIAoFl7Nko+Q3KqAADguz8S27wxoXp3Q7E6AAAisgcAYD+yEQBgvynZiP9/CAAQQjYCAOw35f9+JRsBAEJ+csbAhEQ2AgCEfOSMUQmJbAQACElzxpCERDYCAIR05R4rIZGNAAAhXBsBAPbjcyMAwH7cUwcA2I/vGwEA9uNZDACA/chGAID9yBkAgP3IRgCA/chGAID9yEYAgP3IRgCA/chGAID9yEYAgP3IRgCA/f4HJVsUQMUDEDoAAAAASUVORK5CYII=" alt="" />
a只有一个字符,但比较的时候,是用 a 的第一个字符 'z' 和 b的第一个字符 'a' 比较,因为'z' > 'a' 了,所以整个字符串都大。如果逐一比较时,两个字符相等的话,就比较下一个字符,如果比较到最后都相等,则说明两个字符串的值相等(==)。至于是否是同一对象就需要另外确定。
6.*
字符串的乘法将会返回一个多出重复原字符串的副本。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ4AAABTCAIAAADhtH5vAAADRElEQVR4nO3cUZKrIBCFYXd99zSb9D5MJhJt5ERpaeD/HqYyFKFTRXdEJS5rV5afZflZWn+KDwE/Ejy85vjfYky23vik6nn5m+vmsGIsSmUG2xx3US1+SXl5ZOpkEh/T3EW1OCHjcW6fH3WrZfmj9FE6Zwf5W0SlGX/eeBzBHDAX6MKHRNduFcZ5taRJf60ARLtK+LbR/LfYh2qZje9RZRUOLBWPKrsWs1uug35az4FlTr7nKu+8dz2qbOFK3/r3S8U8QGEGjlfAWIBhJL73Ve6vrKQo1un7mlkpnZ/9p0VVvFRAtUyFyQYklAogoVQACaUCSDrcLul8kQAwBdouqWT/YxeggZ0Q2yV/kz79q78LeEb77ZLf9kzfoncGboqyXfKrUuFcBc9rv11yZQGGHgTaLvlt6lMqeFJn2yW5AoZW+tsuyX0VNEHCARJKBZBQKoDkfYVqZfEfB9MRUHpBqfbQS3bKH8iD3qNTKtFsRxWvAE2nvNPo1ElA7nPSabIOEB11FbdmGWuJ88bjCOaAuUBER0znW7OM13qj+W+xz4VA40VHQNJRZddidst10E9tc9/Wc0ZHNOJuLvu10kFMF/NLmuiIgwVYxOgIqFAq5sJAbEzfniaWOeyxfeboCIiZASSUCiChVAAJpQJIXqXi/SvIax8OiGNL4ua/raeiENlHdvo9XdLj4UbAk/Z56bcSK3bwew4lcN+twtCfxSp2UyrKfA14C3FU+XYBxoEFzwtxrqL3SbtRKnhSoCtgrcYEFP3dV/F4YiVQRKoBEkoFkFAqgOR9NYkfFQXCdASUXlCqPXTnz3dsG51SiWY7qngFaDrlnUanTgJyn5NOk3WA6KiruOeq8NiEY+NxBHPAXCCiI6bzrVnGa73R/LfY50Kg8aIjIOmosmsxu+U66Ke2uW/rOaMjGnE3l/1a6SCmi/klTXTEwQIsYnQEVCgVc2EgNqZvTxPLHPbYPnN0BMTMABJKBZC4lAq/JMF4KBVA8kroJk9pATqyJXTFaqFUMJ6PhK5VLZQKxrNP6CrVQqlgPLcKI1ctlArGw1EFkHCuAki4AgZIuK8CSLhbD0goFUBCQgMSSgWQUCqAhFIBJJQKIKFUAMl/XRfL1AaMOuIAAAAASUVORK5CYII=" alt="" />
只能和数字相乘,字符串间相乘是不可以的。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaIAAAA/CAIAAAAt5lsRAAAC9UlEQVR4nO3dy1riQBAG0Lz1vJMvGRcqAhOTvoZKcc5iFnxNKhb0b249LitAasurd6DLsnzv//KxLB9FP8ulR95+XqDc77T5tzWFyl8839OcL4yPnpE7IXVC9e8XYzQfLuRhzlwr6e4n/HkpU/zijOqrmIN6z3PmKkn3qtlenlMT90HSQY2uUCtJuuVHyZiSwbe3HI5Zf04zB2bTbYNj865qs2IOqmxPmFFJ93BeOXRyFkXhXWSMSqUI2xRzUGX60dxacEA372huHX1ANzvmisaLOagx/drc7zMfpx/NrXcJIubgbc290zrvpLVkg+WRVHgI+fJtrjIO6k1/bq72bLRqy8dj7i7tH6ZSUdE59wrcf4B5rj1nRs35GdlxlW1CeqYNkJyYA5ITc0Byl1y6P+OGBpBVrKX7tQ8GSzrgUJSl+1+Bdf9v+bsAdoRYul878v4t5YOB9xRo6X5VzLk2BxQKsXR/ddIKTBNr6X5tbIk54ND1lu670wpUueTSfc/NAeUkBZCcmAOSE3NActsxd7vqtSxr4RWw8pGdb1dIoXcr5Cp0p43+PfW0vMWdH8b/df/a4NhCQ0aGKqR1zYXCtk7S9TiIudd+rWd83uknau2LnYU6RwYsFLN1Yq7Hc/NCdTPUzlyL1jUL27qwOxZfY8x9HdvP7vutygkf8Gm1tK6/0DlVorVOzDVribm2s9oGCimkUNUYNrWftJ7wG+8lX7gTaF1PubdtnZhr1n7SWjW+Tdgv3JBaWtdc6z1bJ+aaHT9Qsj9gf3DnL16FFFKocAA7WmJufbx0evhVaHbmBdrzC2ldcyGto8p280b19LTPRiGFFOIv+gckNyvm/H9wQBBiDkjuN4lm/N3Cnj0DGOIhiQYmnZgDgnhOooF/oVXMARF0hdpO0ok5IIjtJOpPOjEHBOFoDkjOtTkgOXdageQ8NwckZxUEkJyYA5KTREByYg5ITswByYk5IDkxByQn5oDkxByQnJgDkhNzQHJiDkhOzAHJfQLeRk5pVvKuiQAAAABJRU5ErkJggg==" alt="" />
也没有什么“乘法分配率”的说法,这样只是重复元祖而已。
7.%
取模运算符就是字符串格式化时使用的符号。
关于剩下的内置方法,我会另起一篇进行总结分析。