python2 字符串函数_python基础(二)字符串內建函数详解

1 def capitalize(self): #real signature unknown; restored from __doc__

2 """

3 B.capitalize() -> copy of B4 把字符串的第一个字符大写5 Return a copy of B with only its first character capitalized (ASCII)6 and the rest lower-cased.7 """

8 pass

9

10 def center(self, width, fillchar=None): #real signature unknown; restored from __doc__

11 """

12 B.center(width[, fillchar]) -> copy of B13 返回一个原字符串居中,并使用空格填充至长度width的新字符14 Return B centered in a string of length width. Padding is15 done using the specified fill character (default is a space).16 """

17 pass

18

19 def count(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

20 """

21 B.count(sub[, start[, end]]) -> int22 返回str在string里面出现的次数,如果start或者end指定则返回指定范围内str出现的次数23 Return the number of non-overlapping occurrences of subsection sub in24 bytes B[start:end]. Optional arguments start and end are interpreted25 as in slice notation.26 """

27 return028

29 def encode(self, encoding='utf-8', errors='strict'): #real signature unknown; restored from __doc__

30 """

31 S.encode(encoding='utf-8', errors='strict') -> bytes32 以encoding 指定的编码格式解码string,如果出错默认报一个ValueError的异常,除非errors指定的是‘ignore’或者replace33 Encode S using the codec registered for encoding. Default encoding34 is 'utf-8'. errors may be given to set a different error35 handling scheme. Default is 'strict' meaning that encoding errors raise36 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and37 'xmlcharrefreplace' as well as any other name registered with38 codecs.register_error that can handle UnicodeEncodeErrors.39 """

40 pass

41

42 def endswith(self, suffix, start=None, end=None): #real signature unknown; restored from __doc__

43 """

44 B.endswith(suffix[, start[, end]]) -> bool45 检查字符串是否以suffix结束,如果start或者end指定则检查指定的范围内是否以suffix结束,如果是返回True,否则返回False46 Return True if B ends with the specified suffix, False otherwise.47 With optional start, test B beginning at that position.48 With optional end, stop comparing B at that position.49 suffix can also be a tuple of bytes to try.50 """

51 returnFalse52

53 def expandtabs(self, tabsize=8): #real signature unknown; restored from __doc__

54 """

55 B.expandtabs(tabsize=8) -> copy of B56 把字符串string中的tab符号\t转换为空格,默认的空格数tabsize是857 Return a copy of B where all tab characters are expanded using spaces.58 If tabsize is not given, a tab size of 8 characters is assumed.59 """

60 pass

61

62 def insert(self, *args, **kwargs): #real signature unknown

63 """

64 Insert a single item into the bytearray before the given index.65

66 index67 The index where the value is to be inserted.68 item69 The item to be inserted.70 """

71 pass

72

73 def isalnum(self): #real signature unknown; restored from __doc__

74 """

75 B.isalnum() -> bool76 如果string至少有一个字符并且所有字符都是字母或数字则返回True,否则返回False77 Return True if all characters in B are alphanumeric78 and there is at least one character in B, False otherwise.79 """

80 returnFalse81

82 def isalpha(self): #real signature unknown; restored from __doc__

83 """

84 B.isalpha() -> bool85 如果string至少有一个字符并且所有字符都是字母则返回True,否则返回False86 Return True if all characters in B are alphabetic87 and there is at least one character in B, False otherwise.88 """

89 returnFalse90

91 def isdigit(self): #real signature unknown; restored from __doc__

92 """

93 B.isdigit() -> bool94 如果string只包含十进制数字则返回True,否则返回False95 Return True if all characters in B are digits96 and there is at least one character in B, False otherwise.97 """

98 returnFalse99

100 def islower(self): #real signature unknown; restored from __doc__

101 """

102 B.islower() -> bool103 如果string中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是小写,则返回True,否则返回False104 Return True if all cased characters in B are lowercase and there is105 at least one cased character in B, False otherwise.106 """

107 returnFalse108

109 def isspace(self): #real signature unknown; restored from __doc__

110 """

111 B.isspace() -> bool112 如果string中只包含空格,则返回Ture,否则返回False113 Return True if all characters in B are whitespace114 and there is at least one character in B, False otherwise.115 """

116 returnFalse117

118 def istitle(self): #real signature unknown; restored from __doc__

119 """

120 B.istitle() -> bool121 如果string是标题化的(就是首字母大写)则返回True,否则返回False122 Return True if B is a titlecased string and there is at least one123 character in B, i.e. uppercase characters may only follow uncased124 characters and lowercase characters only cased ones. Return False125 otherwise.126 """

127 returnFalse128

129 def isupper(self): #real signature unknown; restored from __doc__

130 """

131 B.isupper() -> bool132 如果string中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是大写,则返回True,否则返回False133 Return True if all cased characters in B are uppercase and there is134 at least one cased character in B, False otherwise.135 """

136 returnFalse137

138 def join(self, *args, **kwargs): #real signature unknown

139 """

140 Concatenate any number of bytes/bytearray objects.141 以string 作为分隔符,将序列中所有的元素(的字符串表示)合并为一个新的字符串142 The bytearray whose method is called is inserted in between each pair.143

144 The result is returned as a new bytearray object.145 """

146 pass

147

148 def ljust(self, width, fillchar=None): #real signature unknown; restored from __doc__

149 """

150 B.ljust(width[, fillchar]) -> copy of B151 返回一个原字符左对齐,并使用空格填充至长度width的新字符串152 Return B left justified in a string of length width. Padding is153 done using the specified fill character (default is a space).154 """

155 pass

156

157 def lower(self): #real signature unknown; restored from __doc__

158 """

159 B.lower() -> copy of B160 转换sting中所有大写字符为小写161 Return a copy of B with all ASCII characters converted to lowercase.162 """

163 pass

164

165 def maketrans(*args, **kwargs): #real signature unknown

166 """

167 Return a translation table useable for the bytes or bytearray translate method.168

169 The returned table will be one where each byte in frm is mapped to the byte at170 the same position in to.171

172 The bytes objects frm and to must be of the same length.173 """

174 pass

175

176 def partition(self, sep): #real signature unknown; restored from __doc__

177 """

178 S.partition(sep) -> (head, sep, tail)179 有点像find()和split()的结合体,从str出现的第一个位置起,把字符串string分成一个三字符的元组(string_pre_str,str,180 string_post_str),如果string中不包含str则string_pre_str == string.181 Search for the separator sep in S, and return the part before it,182 the separator itself, and the part after it. If the separator is not183 found, return S and two empty strings.184 """

185 pass

186

187 def pop(self, *args, **kwargs): #real signature unknown

188 """

189 Remove and return a single item from B.190

191 index192 The index from where to remove the item.193 -1 (the default value) means remove the last item.194

195 If no index argument is given, will pop the last item.196 """

197 pass

198

199 def remove(self, *args, **kwargs): #real signature unknown

200 """

201 Remove the first occurrence of a value in the bytearray.202

203 value204 The value to remove.205 """

206 pass

207

208 def replace(self, old, new, count=None): #real signature unknown; restored from __doc__

209 """

210 S.replace(old, new[, count]) -> str211 把string中的old替换成new,如果count指定,则替换不超过count次212 Return a copy of S with all occurrences of substring213 old replaced by new. If the optional argument count is214 given, only the first count occurrences are replaced.215 """

216 return ""

217 def reverse(self, *args, **kwargs): #real signature unknown

218 """Reverse the order of the values in B in place."""

219 pass

220

221 def find(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

222 """

223 B.find(sub[, start[, end]]) -> int224 检测str是否包含在string中,如果start和end指定范围,则检查是否包含在指定范围内,如果是返回开始的索引值,否则返回-1225 Return the lowest index in B where subsection sub is found,226 such that sub is contained within B[start,end]. Optional227 arguments start and end are interpreted as in slice notation.228

229 Return -1 on failure.230 """

231 return0232

233 def rfind(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

234 """

235 B.rfind(sub[, start[, end]]) -> int236 类似于find()函数,不过是从右边开始查找237 Return the highest index in B where subsection sub is found,238 such that sub is contained within B[start,end]. Optional239 arguments start and end are interpreted as in slice notation.240

241 Return -1 on failure.242 """

243 return0244

245 def index(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

246 """

247 B.index(sub[, start[, end]]) -> int248 跟find()方法一样,只不过如果str不在string中会报一个异常249 Like B.find() but raise ValueError when the subsection is not found.250 """

251 return0252

253 def rindex(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

254 """

255 B.rindex(sub[, start[, end]]) -> int256 类似于index(),不过是从右边开始257 Like B.rfind() but raise ValueError when the subsection is not found.258 """

259 return0260

261 def rjust(self, width, fillchar=None): #real signature unknown; restored from __doc__

262 """

263 B.rjust(width[, fillchar]) -> copy of B264 返回一个原字符串右对齐,并使用空格填充至长度width的新字符串265 Return B right justified in a string of length width. Padding is266 done using the specified fill character (default is a space)267 """

268 pass

269

270 def rpartition(self, sep): #real signature unknown; restored from __doc__

271 """

272 S.rpartition(sep) -> (head, sep, tail)273 类似于partition()函数,不过是从右边开始查找274 Search for the separator sep in S, starting at the end of S, and return275 the part before it, the separator itself, and the part after it. If the276 separator is not found, return two empty strings and S.277 """

278 pass

279

280 def strip(self, chars=None): #real signature unknown; restored from __doc__

281 """

282 S.strip([chars]) -> str283 删除string字符串左右两边的空格、\n回车284 Return a copy of the string S with leading and trailing285 whitespace removed.286 If chars is given and not None, remove characters in chars instead.287 """

288 return ""

289

290 def rstrip(self, *args, **kwargs): #real signature unknown

291 """

292 Strip trailing bytes contained in the argument.293 删除string字符串末尾的空格294 If the argument is omitted or None, strip trailing ASCII whitespace.295 """

296 pass

297

298 def lstrip(self, chars=None): #real signature unknown; restored from __doc__

299 """

300 S.lstrip([chars]) -> str301 截掉string左边的空格302 Return a copy of the string S with leading whitespace removed.303 If chars is given and not None, remove characters in chars instead.304 """

305 return ""

306

307 def split(self, sep=None, maxsplit=-1): #real signature unknown; restored from __doc__

308 """

309 S.split(sep=None, maxsplit=-1) -> list of strings310 以seq为分隔符切片string,与partition的区别结果不包含seq,如果maxsplit有指定值,仅分割maxsplit个字符串311 Return a list of the words in S, using sep as the312 delimiter string. If maxsplit is given, at most maxsplit313 splits are done. If sep is not specified or is None, any314 whitespace string is a separator and empty strings are315 removed from the result.316 """

317 return[]318

319 def rsplit(self, sep=None, maxsplit=-1): #real signature unknown; restored from __doc__

320 """

321 S.rsplit(sep=None, maxsplit=-1) -> list of strings322

323 Return a list of the words in S, using sep as the324 delimiter string, starting at the end of the string and325 working to the front. If maxsplit is given, at most maxsplit326 splits are done. If sep is not specified, any whitespace string327 is a separator.328 """

329 return[]330

331 def splitlines(self, keepends=None): #real signature unknown; restored from __doc__

332 """

333 S.splitlines([keepends]) -> list of strings334 按照行分隔,返回一个包含各行作为元素的列表335 Return a list of the lines in S, breaking at line boundaries.336 Line breaks are not included in the resulting list unless keepends337 is given and true.338 """

339 return[]340

341 def startswith(self, prefix, start=None, end=None): #real signature unknown; restored from __doc__

342 """

343 B.startswith(prefix[, start[, end]]) -> bool344 检查字符串是否是以prefix开头,是则返回True,否则返回False。如果start和end指定值,则在指定范围内检查345 Return True if B starts with the specified prefix, False otherwise.346 With optional start, test B beginning at that position.347 With optional end, stop comparing B at that position.348 prefix can also be a tuple of bytes to try.349 """

350 returnFalse351

352 def swapcase(self): #real signature unknown; restored from __doc__

353 """

354 B.swapcase() -> copy of B355 翻转string中大小写356 Return a copy of B with uppercase ASCII characters converted357 to lowercase ASCII and vice versa.358 """

359 pass

360

361 def title(self): #real signature unknown; restored from __doc__

362 """

363 S.title() -> str364 返回“标题化”的string,就是说所有单词都是以大写开始,其余字母均为小写365 Return a titlecased version of S, i.e. words start with title case366 characters, all remaining cased characters have lower case.367 """

368 return ""

369

370 def translate(self, table, deletechars=None): #real signature unknown; restored from __doc__

371 """

372 translate(table, [deletechars])373 根据table的表(包含256个字符)转换string的字符,要过滤掉的字符放到deletechars参数中374 Return a copy with each character mapped by the given translation table.375

376 table377 Translation table, which must be a bytes object of length 256.378

379 All characters occurring in the optional argument deletechars are removed.380 The remaining characters are mapped through the given translation table.381 """

382 pass

383

384 def upper(self): #real signature unknown; restored from __doc__

385 """

386 B.upper() -> copy of B387 转换string中的小写字母为大写388 Return a copy of B with all ASCII characters converted to uppercase.389 """

390 pass

391

392 def zfill(self, width): #real signature unknown; restored from __doc__

393 """

394 B.zfill(width) -> copy of B395 返回长度为width的字符串,原字符串string右对齐,前面填充0396 Pad a numeric string B with zeros on the left, to fill a field397 of the specified width. B is never truncated.398 """

399 pass

400

401 def format(self, *args, **kwargs): #known special case of str.format

402 """

403 S.format(*args, **kwargs) -> str404

405 Return a formatted version of S, using substitutions from args and kwargs.406 The substitutions are identified by braces ('{' and '}').407 """

408 pass

409

410 def format_map(self, mapping): #real signature unknown; restored from __doc__

411 """

412 S.format_map(mapping) -> str413

414 Return a formatted version of S, using substitutions from mapping.415 The substitutions are identified by braces ('{' and '}').416 """

417 return ""

418

419 def isidentifier(self): #real signature unknown; restored from __doc__

420 """

421 S.isidentifier() -> bool422

423 Return True if S is a valid identifier according424 to the language definition.425

426 Use keyword.iskeyword() to test for reserved identifiers427 such as "def" and "class".428 """

429 return False

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值