str文档

文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
class str(object):
    """
    str(object='') -> str
    str(bytes_or_buffer[, encoding[, errors]]) -> str
    ---------------------------------------------------------------------
    Create a new string object from the given object. If encoding or
    errors is specified, then the object must expose a data buffer
    that will be decoded using the given encoding and error handler.
    Otherwise, returns the result of object.__str__() (if defined)
    or repr(object).
    将一个指定的对象转换为字符串形式,几根据一个指定的对象创建一个新的字符串对象。
    另外,str(object)可以返回一个对象的信息说明,
    如果没有,则会调用object对象的__str__()方法
    如:print(str(print))的结果为:<built-in function print>
    ---------------------------------------------------------------------
    encoding defaults to sys.getdefaultencoding().
    errors defaults to 'strict'.
    """
 
    def capitalize(self):  # real signature unknown; restored from __doc__
        """
        S.capitalize() -> str
        ---------------------------------------------------------------------
        Return a capitalized version of S, i.e. make the first character
        have upper case and the rest lower case.
        将一个字符串首字母转换为大写,而且!而且其余字母全部转换为小写
        如:'fuyong'.capitalize()与print('fuyong'.capitalize()的结果均为'Fuyong'
        ---------------------------------------------------------------------
        """
        return ""
 
 
    def center(self, width, fillchar=None):  # real signature unknown; restored from __doc__
        """
        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)
        将字符串居中显示,可以指定总宽度以及填充值,默认用空格填充
        如:print('fuyong'.center(20,'*'))的结果为:'*******fuyong*******'
        ---------------------------------------------------------------------
        """
        return ""
 
    def count(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        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.
        返回一个子字符串在该字符串中出现的次数。参数start和end是可选参数,可以理解为是一个切片
        ---------------------------------------------------------------------
        print('fuxiaoyong'.count('o'))      # 2
        print('fuxiaoyong'.count('o',6))    # 1
        print('fuxiaoyong'.count('o',6,8))  # 1
        ---------------------------------------------------------------------
        """
        return 0
 
    def encode(self, encoding='utf-8', errors='strict'):  # real signature unknown; restored from __doc__
        """
        S.encode(encoding='utf-8', errors='strict') -> bytes
        将一个字符串按照指定的编码方式编码成bytes类型,默认的编码格式为utf-8
        ---------------------------------------------------------------------
        Encode S using the codec registered for encoding. Default encoding
        is 'utf-8'. 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 can handle UnicodeEncodeErrors.
        """
        return b""
 
    def endswith(self, suffix, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        S.endswith(suffix[, start[, end]]) -> bool
        判断一个字符串是否以一个指定后缀结尾,返回一个布尔值
        ---------------------------------------------------------------------
        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.
        如果是以指定的后缀结尾,则返回True,否则返回False
        start和end参数是可选参数。可以指定起始位置与结束位置,在此范围内进行判断,类似于切片的方式
        后缀也可以是一个元组或者字符串,
        如果是一个元组的话,后缀就在元组里选,任意一个元素满足返回True
        ---------------------------------------------------------------------
        print('fuyong'.endswith('g'))          # True
        print('fuyong'.endswith('ong'))        # True
        print('fuyong'.endswith('ong',2))      # True
        print('fuyong'.endswith('ong',1,3))    # False
        print('fuyong'.endswith(('n','g')))    # True
        print('fuyong'.endswith(('n','m')))    # False
        ---------------------------------------------------------------------
        """
        return False
 
    def 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.
        如果一个字符串中包括制表符'\t',那么可以用tabsize参数指定制表符的长度,
        tabsize是可选的,默认值是8个字节
        ---------------------------------------------------------------------
        print('fu\tyong'.expandtabs())      # 'fu      yong'
        print('fu\tyong'.expandtabs(4))     # 'fu  yong'
        ---------------------------------------------------------------------
        """
        return ""
 
    def find(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        S.find(sub[, start[, end]]) -> int
        查找一个子字符串在原字符串中的位置,返回一个int类型的索引值
        ---------------------------------------------------------------------
        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.
        如果在其中能找到(一个或多个)指定字符串,则返回最小索引值的那一个
        意思是从左往右找,返回找到的第一个的索引值
        也可以通过可选参数start和end来指定查找范围
        ---------------------------------------------------------------------
        Return -1 on failure.
        如果找不到,则返回 -1
        ---------------------------------------------------------------------
        print('fuyong'.find('o'))                     # 3
        print('fuyong is a old man'.find('o'))        # 3
        print('fuyong is a old man'.find('o',8))      # 12
        print('fuyong is a old man'.find('o',5,8))    # -1
        ---------------------------------------------------------------------
        """
        return 0
 
    def format(self, *args, **kwargs):  # known special case of str.format
        """
        S.format(*args, **kwargs) -> str
        格式化输出,返回一个str
        ---------------------------------------------------------------------
        Return a formatted version of S, using substitutions from args and kwargs.
        The substitutions are identified by braces ('{' and '}').
        格式化输出一段字符串。用{}的形式来占位
        ---------------------------------------------------------------------
        =根据位置一一填充=
        print('{}今年{}岁,{}是一个春心荡漾的年纪'.format('fuyong',18,18))
 
        =根据索引对应填充=
        print('{0}今年{1}岁,{1}是一个春心荡漾的年纪'.format('fuyong',18))
 
        =根据关键字对应填充=
        print('{name}今年{age}岁,{age}是一个春心荡漾的年纪'.format(name='fuyong',age=18))
 
        =根据列表的索引填充=
        num_list = [3,2,1]
        print('列表的第二个数字是{lst[1]},第三个数字是{lst[2]}'.format(lst=num_list))
 
        =根据字典的key填充=
        info_dict = {'name':'fuyong','age':18}
        print("他的姓名是{dic[name]},年纪是{dic[age]}".format(dic=info_dict))
 
        =根据对象的属性名填充=
        class Person:
            def __init__(self,name,age):
                self.name = name
                self.age = age
        print("他的姓名是{p.name},年纪是{p.age}".format(p=Person('fuyong',18)))
        ---------------------------------------------------------------------
        """
        pass
 
    def index(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        S.index(sub[, start[, end]]) -> int
        返回一个自字符串在原字符串的索引值
        ---------------------------------------------------------------------
        Like S.find() but raise ValueError when the substring is not found.
        跟find()函数类似,不同的是,如果找不到则会直接报错
        ---------------------------------------------------------------------
        """
        return 0
 
    def isalnum(self):  # real signature unknown; restored from __doc__
        """
        S.isalnum() -> bool
 
        Return True if all characters in S are alphanumeric
        and there is at least one character in S, False otherwise.
        判断一个字符串是不是全部由数字或者字母组成,返回一个布尔值
        """
        return False
 
    def isalpha(self):  # real signature unknown; restored from __doc__
        """
        S.isalpha() -> bool
 
        Return True if all characters in S are alphabetic
        and there is at least one character in S, False otherwise.
        判断一个字符串是不是全部由字母组成,返回一个布尔值
        """
        return False
 
    def isdecimal(self):  # real signature unknown; restored from __doc__
        """
        S.isdecimal() -> bool
 
        Return True if there are only decimal characters in S,
        False otherwise.
        判断一个字符串是不是全部由十进制字符组成,返回一个布尔值
        """
        return False
 
    def isdigit(self):  # real signature unknown; restored from __doc__
        """
        S.isdigit() -> bool
 
        Return True if all characters in S are digits
        and there is at least one character in S, False otherwise.
        判断一个字符串是不是全部由数字组成,返回一个布尔值
        """
        return False
 
 
    def islower(self):  # real signature unknown; restored from __doc__
        """
        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.
        判断一个字符串是否全部由小写字母组成,如果有任意一个字符为大写,则返回False
        """
        return False
 
    def isspace(self):  # real signature unknown; restored from __doc__
        """
        S.isspace() -> bool
 
        Return True if all characters in S are whitespace
        and there is at least one character in S, False otherwise.
        判断一个字符串是否全部由空格字母组成
        """
        return False
 
    def istitle(self):  # real signature unknown; restored from __doc__
        """
        S.istitle() -> bool
 
        Return True if S is a titlecased string and there is at least one
        character in S, i.e. upper- and titlecase characters may only
        follow uncased characters and lowercase characters only cased ones.
        Return False otherwise.
        """
        return False
 
    def isupper(self):  # real signature unknown; restored from __doc__
        """
        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.
        判断一个字符串是否全部由大写字母组成,如果有任意一个字符为小写,则返回False
        """
        return False
 
    def 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.
        将一个可迭代对象用指定字符串连接起来
        返回值为一个字符串
        """
        return ""
 
    def ljust(self, width, fillchar=None):  # real signature unknown; restored from __doc__
        """
        S.ljust(width[, fillchar]) -> str
 
        Return S left-justified in a Unicode string of length width. Padding is
        done using the specified fill character (default is a space).
        以左为齐,将一个字符串的右!!右边填充指定字符串,可以指定宽度,默认为用空格填充。
        不会改变原字符串,而会重新生成一个字符串
 
        print('fuyong'.ljust(10,'*'))  # fuyong****
        """
        return ""
 
    def lower(self):  # real signature unknown; restored from __doc__
        """
        S.lower() -> str
 
        Return a copy of the string S converted to lowercase.
        将一个字符串中的字符全部变为小写
        """
        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 ""
 
    def replace(self, old, new, count=None):  # real signature unknown; restored from __doc__
        """
        S.replace(old, new[, count]) -> str
 
        Return a copy of S with all occurrences of substring
        old replaced by new.  If the optional argument count is
        given, only the first count occurrences are replaced.
        将字符串中的某一个子字符串替换为指定字符串
        print('fuyong'.replace('yong','sir'))  #fusir
        """
        return ""
 
    def rfind(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        S.rfind(sub[, start[, end]]) -> int
 
        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.
        与find方法类似,但是是从右边开始查找
 
        Return -1 on failure.
        如果找不到则返回 -1
        """
        return 0
 
    def rindex(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """
        S.rindex(sub[, start[, end]]) -> int
 
        Like S.rfind() but raise ValueError when the substring is not found.
        与index方法类似,但是是从右边开始查找
        如果找不到会直接报错
        """
        return 0
 
    def rjust(self, width, fillchar=None):  # real signature unknown; restored from __doc__
        """
        S.rjust(width[, fillchar]) -> str
 
        Return S right-justified in a string of length width. Padding is
        done using the specified fill character (default is a space).
        以右为齐,将一个字符串的左!!左边填充指定字符串,可以指定宽度,默认为用空格填充。
        print('fuyong'.rjust(10,'*'))  # ****fuyong
        """
        return ""
 
    def rsplit(self, sep=None, maxsplit=-1):  # real signature unknown; restored from __doc__
        """
        S.rsplit(sep=None, maxsplit=-1) -> list of strings
 
        Return a list of the words in 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, any whitespace string
        is a separator.
 
        """
        return []
 
    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 ""
 
    def split(self, sep=None, maxsplit=-1):  # real signature unknown; restored from __doc__
        """
        S.split(sep=None, maxsplit=-1) -> list of strings
 
        Return a list of the words in 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.
        将一个字符串以指定的子字符串进行分割,返回一个列表
        如果找不到指定的子字符串,则会将原字符串直接放到一个列表中
 
        print('fu.yong'.split('.'))     # ['fu', 'yong']
        print('fu.yong'.split('*'))     # ['fu.yong']
        """
        return []
 
 
 
    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.
 
        如果是以指定的字符串结尾,则返回True,否则返回False
        start和end参数是可选参数。可以指定起始位置与结束位置,在此范围内进行判断,类似于切片的方式
        后缀也可以是一个元组或者字符串,
        如果是一个元组的话,后缀就在元组里选,任意一个元素满足返回True
        """
        return False
 
    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 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.
        将一个字符串的大小写反转
        print('u.Yong'.swapcase())  # fU.yONG
        """
        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.
        将一个字符串的!每个单词!首字母大写,并且,其他字母小写
        注意与capitalize的却别
        ---------------------------------------------------------------------
        print('fuYong'.capitalize())    #Fuyong
        print('fu Yong'.capitalize())   #Fu yong
        ---------------------------------------------------------------------
        print('fuYONG'.title())         # Fuyong
        print('fu YONG'.title())        #Fu Yong
        """
        return ""
 
 
    def upper(self):  # real signature unknown; restored from __doc__
        """
        S.upper() -> str
 
        Return a copy of S converted to uppercase.
        将一个字符串的全部字符大写
        """
        return ""
 
    def zfill(self, width):  # real signature unknown; restored from __doc__
        """
        S.zfill(width) -> str
 
        Pad a numeric string S with zeros on the left, to fill a field
        of the specified width. The string S is never truncated.
        将一个字符串按照指定宽度在左侧用0填充
        注意,只填充左侧,而且只能用0填充
        ---------------------------------------------------------------------
        print('fuyong'.zfill(10))   #0000fuyong
        """
        return ""

  

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
print('fuyong'.capitalize())
print('fuyong'.capitalize())
 
print('fuyong'.center(20,'*'))
 
print('fuxiaoyong'.count('o'))
print('fuxiaoyong'.count('o',6))
print('fuxiaoyong'.count('o',6,8))
 
print('fuyong'.endswith('ong'))
print('fuyong'.endswith('ong',2))
print('fuyong'.endswith('ong',1,3))
print('fuyong'.endswith(('n','g')))
print('fuyong'.endswith(('n','g')))
print('fuyong'.endswith(('n','m')))
 
print('fu\tyong'.expandtabs())
print('fu\tyong'.expandtabs(4))
 
print('fuyong'.find('o'))
print('fuyong is a old man'.find('o'))
print('fuyong is a old man'.find('o',8))
print('fuyong is a old man'.find('o',5,8))
 
print('{}今年{}岁,{}是一个春心荡漾的年纪'.format('fuyong',18,18))
print('{0}今年{1}岁,{1}是一个春心荡漾的年纪'.format('fuyong',18))
print('{name}今年{age}岁,{age}是一个春心荡漾的年纪'.format(name='fuyong',age=18))
 
num_list = [3,2,1]
print('列表的第二个数字是{lst[1]},第三个数字是{lst[2]}'.format(lst=num_list))
 
info_dict = {'name':'fuyong','age':18}
print("他的姓名是{dic[name]},年纪是{dic[age]}".format(dic=info_dict))
 
class Person:
    def __init__(self,name,age):
        self.name = name
        self.age = age
print("他的姓名是{p.name},年纪是{p.age}".format(p=Person('fuyong',18)))
 
print('11'.isdecimal())
 
print('fuyong'.rjust(10,'*'))
 
print('fuyong'.replace('yong','sir'))
 
print('fu.yong'.split('.'))
print('fu.yong'.split('*'))
 
print('fu.Yong'.swapcase())
 
print('fuYong'.capitalize())
print('fu Yong'.capitalize())
 
print('fuYONG'.title())
print('fu YONG'.title())
 
print('fuyong'.zfill(10))

  

posted @   人生不如戏  阅读(427)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示