1 class str(basestring):
2 """
3 str(object='') -> string
4
5 Return a nice string representation of the object.
6 If the argument is a string, the return value is the same object.
7 """
8 def capitalize(self): # real signature unknown; restored from __doc__
9 -----第一个字母大写-------
eg:a1="alex"
ret=a1.capitalize()
print(ret)
"""
10 S.capitalize() -> string
11
12 Return a copy of the string S with only its first character
13 capitalized.
14 """
15 return ""
16
17 def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
18 -----以字符串长度宽度为中心返回字符串。 填充的是使用指定的填充字符完成-------
eg:a1="alex"
ret=a1.center(20,"*")
print(ret)
"""
19 S.center(width[, fillchar]) -> string
20
21 Return S centered in a string of length width. Padding is
22 done using the specified fill character (default is a space)
23 """
24 return ""
25
26 def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
27 -----在设定范围内寻找与sub重合的字符个数-------
eg:a1="alex"
ret=a1.count("a",0,3)
print(ret)
"""
28 S.count(sub[, start[, end]]) -> int
29
30 Return the number of non-overlapping occurrences of substring sub in
31 string S[start:end]. Optional arguments start and end are interpreted
32 as in slice notation.
33 """
34 return 0
35
36 def decode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
37 decode的作用是将其他编码的字符串转换成unicode编码
如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码。
"""
38 S.decode([encoding[,errors]]) -> object
39
40 Decodes S using the codec registered for encoding. encoding defaults
41 to the default encoding. errors may be given to set a different error
42 handling scheme. Default is 'strict' meaning that encoding errors raise
43 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
44 as well as any other name registered with codecs.register_error that is
45 able to handle UnicodeDecodeErrors.
46 """
47 return object()
48
49 def encode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
50 encode的作用是将unicode编码转换成其他编码的字符串
如str2.encode('gb2312'),表示将unicode编码的字符串str2转换成gb2312编码。
"""
51 S.encode([encoding[,errors]]) -> object
52
53 Encodes S using the codec registered for encoding. encoding defaults
54 to the default encoding. errors may be given to set a different error
55 handling scheme. Default is 'strict' meaning that encoding errors raise
56 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
57 'xmlcharrefreplace' as well as any other name registered with
58 codecs.register_error that is able to handle UnicodeEncodeErrors.
59 """
60 return object()
61
62 def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
63 ---判断是否在指定范围内以该字符串结尾----
eg:a1="alex"
ret=a1.endwith("a",0,3)
print(ret)
"""
64 S.endswith(suffix[, start[, end]]) -> bool
65
66 Return True if S ends with the specified suffix, False otherwise.
67 With optional start, test S beginning at that position.
68 With optional end, stop comparing S at that position.
69 suffix can also be a tuple of strings to try.
70 """
71 return False
72
73 def expandtabs(self, tabsize=None): # real signature unknown; restored from __doc__
74 ---把tab键转换成空格键,不输入数字默认替换为8个空格键----("\t"代表一个tab键)
eg:a1="alex adac"
ret=a1.expandtabs()
print(ret)
"""
75 S.expandtabs([tabsize]) -> string
76
77 Return a copy of S where all tab characters are expanded using spaces.
78 If tabsize is not given, a tab size of 8 characters is assumed.
79 """
80 return ""
81
82 def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
83 ---找到子序列所在位置,没有找到则返回-1----
eg:a1="alex adac"
ret=a1.find("a",0)
print(find)
"""
84 S.find(sub [,start [,end]]) -> int
85
86 Return the lowest index in S where substring sub is found,
87 such that sub is contained within S[start:end]. Optional
88 arguments start and end are interpreted as in slice notation.
89
90 Return -1 on failure.
91 """
92 return 0
93
94 def format(self, *args, **kwargs): # known special case of str.format
95 -----字符串格式化,替换占位符。
eg:s="hello{0},age{1}"
print(s)
new1=s.format("alex",19)
print(new1)
"""
96 S.format(*args, **kwargs) -> string
97
98 Return a formatted version of S, using substitutions from args and kwargs.
99 The substitutions are identified by braces ('{' and '}').
使用来自args和kwargs的替换,返回格式化的S版本。替换由大括号('{'和'}')标识。
100 """
101 pass
102
103 def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
104
"""
105 S.index(sub [,start [,end]]) -> int
106
107 Like S.find() but raise ValueError when the substring is not found.
108 """
109 return 0
110
111 def isalnum(self): # real signature unknown; restored from __doc__
112 -----是否是数字和字母------
eg:s="asc1"
temp=s.isalnum()
print(temp)
"""
113 S.isalnum() -> bool
114
115 Return True if all characters in S are alphanumeric
116 and there is at least one character in S, False otherwise.
117 """
118 return False
119
120 def isalpha(self): # real signature unknown; restored from __doc__
121 -----是否是字母------
eg:s="asc1"
temp=s.isalpha()
print(temp)
"""
122 S.isalpha() -> bool
123
124 Return True if all characters in S are alphabetic
125 and there is at least one character in S, False otherwise.
126 """
127 return False
128
129 def isdigit(self): # real signature unknown; restored from __doc__
130 -----是否是数字------
eg:s="asc1"
temp=s.isdigit()
print(temp)
"""
131 S.isdigit() -> bool
132
133 Return True if all characters in S are digits
134 and there is at least one character in S, False otherwise.
135 """
136 return False
137
138 def islower(self): # real signature unknown; restored from __doc__
139 -----是否是小写------
eg:s="asc1"
temp=s.islower()
print(temp)
"""
140 S.islower() -> bool
141
142 Return True if all cased characters in S are lowercase and there is
143 at least one cased character in S, False otherwise.
144 """
145 return False
146
147 def isspace(self): # real signature unknown; restored from __doc__
148 -----如果S中的所有字符都是空格,则返回True S中至少有一个字符,否则为False------
eg:s="asc1"
temp=s.isspace()
print(temp)
"""
149 S.isspace() -> bool
150
151 Return True if all characters in S are whitespace
152 and there is at least one character in S, False otherwise.
153 """
154 return False
155
156 def istitle(self): # real signature unknown; restored from __doc__
157 -----判断是否是标题------
eg:s="asc1"
temp=s.istitle()
print(temp)
"""
158 S.istitle() -> bool
159
160 Return True if S is a titlecased string and there is at least one
161 character in S, i.e. uppercase characters may only follow uncased
162 characters and lowercase characters only cased ones. Return False
163 otherwise.
164 """
165 return False
166
167 def isupper(self): # real signature unknown; restored from __doc__
168 -----检验是否全是大写------
eg:s="asc1"
temp=s.isupper()
print(temp)
"""
169 S.isupper() -> bool
170
171 Return True if all cased characters in S are uppercase and there is
172 at least one cased character in S, False otherwise.
173 """
174 return False
175
176 def join(self, iterable): # real signature unknown; restored from __doc__
177 -----用指定符号把字符串连接起来-----
eg:s="asc1,ascda"
#s=["asc1,ascda"]也支持
#s=("asc1,ascda")也支持
temp="_".join(s)
print(temp)
"""
178 S.join(iterable) -> string
179
180 Return a string which is the concatenation of the strings in the
181 iterable. The separator between elements is S.
182 """
183 return ""
184
185 def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
186 -----内容左对齐,右侧填充-----
eg:s="asc1,ascda"
temp=s.ljust(20,"00")
print(temp)
"""
187 S.ljust(width[, fillchar]) -> string
188
189 Return S left-justified in a string of length width. Padding is
190 done using the specified fill character (default is a space).
191 """
192 return ""
193
194 def lower(self): # real signature unknown; restored from __doc__
195 -----变小写-----
eg:s="ALS1,SXCc"
temp=s.lower()
print(temp)
"""
196 S.lower() -> string
197
198 Return a copy of the string S converted to lowercase.
199 """
200 return ""
201
202 def lstrip(self, chars=None): # real signature unknown; restored from __doc__
203 -----移除左边空格-----
eg:s="ALS1,SXCc"
temp=s.lstrip()#移除左边空格
temp=s.rstrip()#移除右边空格
temp=s.strip()#移除全部空格
print(temp)
"""
204 S.lstrip([chars]) -> string or unicode
205
206 Return a copy of the string S with leading whitespace removed.
207 If chars is given and not None, remove characters in chars instead.
208 If chars is unicode, S will be converted to unicode before stripping
209 """
210 return ""
211
212 def partition(self, sep): # real signature unknown; restored from __doc__
213 ----分割,前,中,后三部分----
eg:s="ALS1SBascda"
temp=s.partition("SB")
print(temp)
//('Asc1', 'SB', 'ascda')
"""
214 S.partition(sep) -> (head, sep, tail)
215
216 Search for the separator sep in S, and return the part before it,
217 the separator itself, and the part after it. If the separator is not
218 found, return S and two empty strings.
219 """
220 pass
221
222 def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
213 ----( 替换用旧的换新的)----
eg:s="ALS1SBascda"
temp=s.partition("al","SB",1)
print(temp)
"""
224 S.replace(old, new[, count]) -> string
225
226 Return a copy of string S with all occurrences of substring
227 old replaced by new. If the optional argument count is
228 given, only the first count occurrences are replaced.
229 """
230 return ""
231
232 def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
233 ---从右向左找到子序列所在位置,没有找到则返回-1----
eg:a1="alex adac"
ret=a1.rfind("a",0)
print(ret)
"""
234 S.rfind(sub [,start [,end]]) -> int
235
236 Return the highest index in S where substring sub is found,
237 such that sub is contained within S[start:end]. Optional
238 arguments start and end are interpreted as in slice notation.
239
240 Return -1 on failure.
241 """
242 return 0
243
244 def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
---从右向左找到子序列所在----
eg:a1="alex adac"
ret=a1.rindex("a",0)
print(ret)
245 """
246 S.rindex(sub [,start [,end]]) -> int
247
248 Like S.rfind() but raise ValueError when the substring is not found.
249 """
250 return 0
251
252 def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
---返回S右对齐的长度宽度的字符串。 填充是使用指定的填充字符完成(默认是空格)----
eg:a1="alexadac"
ret=a1.rjust(10,"a")
print(ret)
253 """
254 S.rjust(width[, fillchar]) -> string
255
256 Return S right-justified in a string of length width. Padding is
257 done using the specified fill character (default is a space)
258 """
259 return ""
260
261 def rpartition(self, sep): # real signature unknown; restored from __doc__
262 在字符串的末尾搜索字符串中的分隔符sep并返回之前的部分,分隔符本身,以及之后的部分。 如果
分隔符未找到,返回两个空字符串和S.
a1="alexadac"
ret=a1.rpartition(a)
print(ret)
"""
263 S.rpartition(sep) -> (head, sep, tail)
264
265 Search for the separator sep in S, starting at the end of S, and return
266 the part before it, the separator itself, and the part after it. If the
267 separator is not found, return two empty strings and S.
268 """
269 pass
270
271 def rsplit(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
272 -----从右向左找用字符串内指定字符分割字符串,即指定字符换成逗号----
a1="alexadac"
ret=a1.rsplit("a")
print(ret)
"""
273 S.rsplit([sep [,maxsplit]]) -> list of strings
274
275 Return a list of the words in the string S, using sep as the
276 delimiter string, starting at the end of the string and working
277 to the front. If maxsplit is given, at most maxsplit splits are
278 done. If sep is not specified or is None, any whitespace string
279 is a separator.
280 """
281 return []
282
283 def rstrip(self, chars=None): # real signature unknown; restored from __doc__
284 从右向左,,移除空白
"""
285 S.rstrip([chars]) -> string or unicode
286
287 Return a copy of the string S with trailing whitespace removed.
288 If chars is given and not None, remove characters in chars instead.
289 If chars is unicode, S will be converted to unicode before stripping
290 """
291 return ""
292
293 def split(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
294 ----根据自定义字符分割-----
"""
295 S.split([sep [,maxsplit]]) -> list of strings
296
297 Return a list of the words in the string S, using sep as the
298 delimiter string. If maxsplit is given, at most maxsplit
299 splits are done. If sep is not specified or is None, any
300 whitespace string is a separator and empty strings are removed
301 from the result.
302 """
303 return []
304
305 def splitlines(self, keepends=False): # real signature unknown; restored from __doc__
306 ------根据换行符分割------
"""
307 S.splitlines(keepends=False) -> list of strings
308
309 Return a list of the lines in S, breaking at line boundaries.
310 Line breaks are not included in the resulting list unless keepends
311 is given and true.
312 """
313 return []
314
315 def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
316 ----判断字符串是否以某一字符开始----
"""
317 S.startswith(prefix[, start[, end]]) -> bool
318
319 Return True if S starts with the specified prefix, False otherwise.
320 With optional start, test S beginning at that position.
321 With optional end, stop comparing S at that position.
322 prefix can also be a tuple of strings to try.
323 """
324 return False
325
326 def strip(self, chars=None): # real signature unknown; restored from __doc__
327 ----移除两段空白---
"""
328 S.strip([chars]) -> string or unicode
329
330 Return a copy of the string S with leading and trailing
331 whitespace removed.
332 If chars is given and not None, remove characters in chars instead.
333 If chars is unicode, S will be converted to unicode before stripping
334 """
335 return ""
336
337 def swapcase(self): # real signature unknown; restored from __doc__
338 ---大写变小写,小写变大写-----
"""
339 S.swapcase() -> string
340
341 Return a copy of the string S with uppercase characters
342 converted to lowercase and vice versa.
343 """
344 return ""
345
346 def title(self): # real signature unknown; restored from __doc__
347 ----把你变标题----
"""
348 S.title() -> string
349
350 Return a titlecased version of S, i.e. words start with uppercase
351 characters, all remaining cased characters have lowercase.
352 """
353 return ""
354
355 def translate(self, table, deletechars=None): # real signature unknown; restored from __doc__
356 """
357 S.translate(table [,deletechars]) -> string
358
359 Return a copy of the string S, where all characters occurring
360 in the optional argument deletechars are removed, and the
361 remaining characters have been mapped through the given
362 translation table, which must be a string of length 256 or None.
363 If the table argument is None, no translation is applied and
364 the operation simply removes the characters in deletechars.
365 """
366 return ""
367
368 def upper(self): # real signature unknown; restored from __doc__
369 ----变大写---
"""
370 S.upper() -> string
371
372 Return a copy of the string S converted to uppercase.
373 """
374 return ""
375
376 def zfill(self, width): # real signature unknown; restored from __doc__
377 --方法返回指定长度的字符串,元字符串右对齐,前面填充0.
"""
378 S.zfill(width) -> string
379
380 Pad a numeric string S with zeros on the left, to fill a field
381 of the specified width. The string S is never truncated.
382 """
383 return ""
2. 字符串指定字符输出
s="alex"
print(s[0])
print(s[1])
print(s[2])
print(s[3])
2.1while循环输出
s="Alex"
start=0
whil start<len(s)
temp=s[start]
print(temp)
start+=1
2.2for循环 break,continue
s="Alex"
for item in s:
print(item)
s="Alex"
for item in s:
if item=="1":
continue
print(item)
3.字符串长度
print(ret)
4.字符串切片
s="ascfdasvc"
print(s[0:4])
浙公网安备 33010602011771号