标签:bool lex set cal err format nec any mod
Python全栈开发【基础二】 |
本节内容:
Python 运算符 |
1、算术运算:
2、比较运算:
3、赋值运算:
4、逻辑运算:
5、成员运算:
基本数据类型 |
1、数字
int(整型)
1 class int(object): 2 """ 3 int(x=0) -> integer 4 int(x, base=10) -> integer 5 6 Convert a number or string to an integer, or return 0 if no arguments 7 are given. If x is a number, return x.__int__(). For floating point 8 numbers, this truncates towards zero. 9 10 If x is not a number or if base is given, then x must be a string, 11 bytes, or bytearray instance representing an integer literal in the 12 given base. The literal can be preceded by ‘+‘ or ‘-‘ and be surrounded 13 by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. 14 Base 0 means to interpret the base from the string as an integer literal. 15 >>> int(‘0b100‘, base=0) 16 """ 17 def bit_length(self): # real signature unknown; restored from __doc__ 18 """ 19 int.bit_length() -> int 20 21 Number of bits necessary to represent self in binary. 22 """ 23 """ 24 表示该数字返回时占用的最少位数 25 26 >>> (951).bit_length() 27 """ 28 return 0 29 30 def conjugate(self, *args, **kwargs): # real signature unknown 31 """ Returns self, the complex conjugate of any int.""" 32 33 """ 34 返回该复数的共轭复数 35 36 #返回复数的共轭复数 37 >>> (95 + 11j).conjugate() 38 (95-11j) 39 #返回复数的实数部分 40 >>> (95 + 11j).real 41 95.0 42 #返回复数的虚数部分 43 >>> (95 + 11j).imag 44 11.0 45 """ 46 pass 47 48 @classmethod # known case 49 def from_bytes(cls, bytes, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 50 """ 51 int.from_bytes(bytes, byteorder, *, signed=False) -> int 52 53 Return the integer represented by the given array of bytes. 54 55 The bytes argument must be a bytes-like object (e.g. bytes or bytearray). 56 57 The byteorder argument determines the byte order used to represent the 58 integer. If byteorder is ‘big‘, the most significant byte is at the 59 beginning of the byte array. If byteorder is ‘little‘, the most 60 significant byte is at the end of the byte array. To request the native 61 byte order of the host system, use `sys.byteorder‘ as the byte order value. 62 63 The signed keyword-only argument indicates whether two‘s complement is 64 used to represent the integer. 65 """ 66 """ 67 这个方法是在Python3.2的时候加入的,python官方给出了下面几个例子: 68 >>> int.from_bytes(b‘\x00\x10‘, byteorder=‘big‘) 69 >>> int.from_bytes(b‘\x00\x10‘, byteorder=‘little‘) 70 >>> int.from_bytes(b‘\xfc\x00‘, byteorder=‘big‘, signed=True) 71 -1024 72 >>> int.from_bytes(b‘\xfc\x00‘, byteorder=‘big‘, signed=False) 73 >>> int.from_bytes([255, 0, 0], byteorder=‘big‘) 74 """ 75 pass 76 77 def to_bytes(self, length, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 78 """ 79 int.to_bytes(length, byteorder, *, signed=False) -> bytes 80 81 Return an array of bytes representing an integer. 82 83 The integer is represented using length bytes. An OverflowError is 84 raised if the integer is not representable with the given number of 85 bytes. 86 87 The byteorder argument determines the byte order used to represent the 88 integer. If byteorder is ‘big‘, the most significant byte is at the 89 beginning of the byte array. If byteorder is ‘little‘, the most 90 significant byte is at the end of the byte array. To request the native 91 byte order of the host system, use `sys.byteorder‘ as the byte order value. 92 93 The signed keyword-only argument determines whether two‘s complement is 94 used to represent the integer. If signed is False and a negative integer 95 is given, an OverflowError is raised. 96 """ 97 """ 98 python官方给出了下面几个例子: 99 >>> (1024).to_bytes(2, byteorder=‘big‘) 100 b‘\x04\x00‘ 101 >>> (1024).to_bytes(10, byteorder=‘big‘) 102 b‘\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00‘ 103 >>> (-1024).to_bytes(10, byteorder=‘big‘, signed=True) 104 b‘\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00‘ 105 >>> x = 1000 106 >>> x.to_bytes((x.bit_length() // 8) + 1, byteorder=‘little‘) 107 b‘\xe8\x03‘ 108 """ 109 pass 110 111 def __abs__(self, *args, **kwargs): # real signature unknown 112 """ abs(self)""" 113 114 """ 115 返回一个绝对值 116 117 >>> (95).__abs__() 118 -95 119 >>> (-95).__abs__() 120 """ 121 pass 122 123 124 def __add__(self, *args, **kwargs): # real signature unknown 125 """ Return self+value.""" 126 127 """ 128 加法,也可区分数字和字符串 129 130 >>> (95).__add__(1) 131 >>> (95).__add__("1") 132 NotImplemented 133 >>> 134 """ 135 pass 136 137 def __and__(self, *args, **kwargs): # real signature unknown 138 """ Return self&value.""" 139 pass 140 141 def __bool__(self, *args, **kwargs): # real signature unknown 142 """ self != 0 """ 143 144 """ 145 判断一个整数对象是否为0,如果为0,则返回False,如果不为0,则返回True 146 147 >>> (95).__bool__() 148 True 149 >>> (0).__bool__() 150 False 151 """ 152 pass 153 154 def __ceil__(self, *args, **kwargs): # real signature unknown 155 """ Ceiling of an Integral returns itself. """ 156 pass 157 158 def __divmod__(self, *args, **kwargs): # real signature unknown 159 """ Return divmod(self, value). """ 160 """ 161 返回一个元组,第一个元素为商,第二个元素为余数 162 163 >>> (9).__divmod__(5) 164 (1, 4) 165 """ 166 pass 167 168 def __eq__(self, *args, **kwargs): # real signature unknown 169 """ Return self==value. """ 170 """ 171 判断两个值是否相等 172 173 >>> (95).__eq__(95) 174 True 175 >>> (95).__eq__(9) 176 False 177 """ 178 pass 179 180 def __float__(self, *args, **kwargs): # real signature unknown 181 """ float(self) """ 182 """ 183 将一个整数转换成浮点型 184 185 >>> (95).__float__() 186 95.0 187 """ 188 pass 189 190 def __floordiv__(self, *args, **kwargs): # real signature unknown 191 """ Return self//value. """ 192 """ 193 整除,保留结果的整数部分 194 195 >>> (95).__floordiv__(9) 196 """ 197 pass 198 199 def __floor__(self, *args, **kwargs): # real signature unknown 200 """ Flooring an Integral returns itself. """ 201 """ 202 返回本身 203 204 >>> (95).__floor__() 205 """ 206 pass 207 208 def __format__(self, *args, **kwargs): # real signature unknown 209 """ 210 转换对象的类型 211 212 >>> (95).__format__(‘f‘) 213 ‘95.000000‘ 214 >>> (95).__format__(‘b‘) 215 ‘1011111‘ 216 """ 217 pass 218 219 220 def __getattribute__(self, *args, **kwargs): # real signature unknown 221 """ Return getattr(self, name). """ 222 """ 223 判断这个类中是否包含这个属性,如果包含则打印出值,如果不包含,就报错了 224 225 >>> (95).__getattribute__(‘__abs__‘) 226 <method-wrapper ‘__abs__‘ of int object at 0x9f93c0> 227 >>> (95).__getattribute__(‘__aaa__‘) 228 Traceback (most recent call last): 229 File "<stdin>", line 1, in <module> 230 AttributeError: ‘int‘ object has no attribute ‘__aaa__‘ 231 """ 232 pass 233 234 def __getnewargs__(self, *args, **kwargs): # real signature unknown 235 pass 236 237 def __ge__(self, *args, **kwargs): # real signature unknown 238 """ Return self>=value. """ 239 """ 240 判断是否大于等于 241 242 >>> (95).__ge__(9) 243 True 244 >>> (95).__ge__(99) 245 False 246 """ 247 pass 248 249 def __gt__(self, *args, **kwargs): # real signature unknown 250 """ Return self>value. """ 251 """ 252 判断是否大于 253 254 >>> (95).__gt__(9) 255 True 256 >>> (95).__gt__(99) 257 False 258 """ 259 pass 260 261 def __hash__(self, *args, **kwargs): # real signature unknown 262 """ Return hash(self). """ 263 """ 264 计算哈希值,整数返回本身 265 266 >>> (95).__hash__() 267 >>> (95.95).__hash__() 268 """ 269 pass 270 271 def __index__(self, *args, **kwargs): # real signature unknown 272 """ Return self converted to an integer, if self is suitable for use as an index into a list. """ 273 pass 274 275 def __init__(self, x, base=10): # known special case of int.__init__ 276 """ 277 这个是一个类的初始化方法,当int类被实例化的时候,这个方法默认就会被执行 278 """ 279 """ 280 int(x=0) -> integer 281 int(x, base=10) -> integer 282 283 Convert a number or string to an integer, or return 0 if no arguments 284 are given. If x is a number, return x.__int__(). For floating point 285 numbers, this truncates towards zero. 286 287 If x is not a number or if base is given, then x must be a string, 288 bytes, or bytearray instance representing an integer literal in the 289 given base. The literal can be preceded by ‘+‘ or ‘-‘ and be surrounded 290 by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. 291 Base 0 means to interpret the base from the string as an integer literal. 292 >>> int(‘0b100‘, base=0) 293 # (copied from class doc) 294 """ 295 pass 296 297 def __int__(self, *args, **kwargs): # real signature unknown 298 """ int(self) """ 299 """ 300 转换为整型 301 302 >>> (9.5).__int__() 303 """ 304 pass 305 306 307 def __invert__(self, *args, **kwargs): # real signature unknown 308 """ ~self """ 309 310 pass 311 312 def __le__(self, *args, **kwargs): # real signature unknown 313 """ Return self<=value. """ 314 """ 315 判断是否小于等于 316 317 >>> (95).__le__(99) 318 True 319 >>> (95).__le__(9) 320 False 321 """ 322 pass 323 324 def __lshift__(self, *args, **kwargs): # real signature unknown 325 """ Return self<<value. """ 326 """ 327 用于二进制位移,这个是向左移动 328 329 >>> bin(95) 330 ‘0b1011111‘ 331 >>> a = (95).__lshift__(2) 332 >>> bin(a) 333 ‘0b101111100‘ 334 >>> 335 """ 336 pass 337 338 def __lt__(self, *args, **kwargs): # real signature unknown 339 """ Return self<value. """ 340 """ 341 判断是否小于 342 343 >>> (95).__lt__(9) 344 False 345 >>> (95).__lt__(99) 346 True 347 """ 348 pass 349 350 def __mod__(self, *args, **kwargs): # real signature unknown 351 """ Return self%value. """ 352 """ 353 取模 % 354 355 >>> (95).__mod__(9) 356 """ 357 pass 358 359 def __mul__(self, *args, **kwargs): # real signature unknown 360 """ Return self*value. """ 361 """ 362 乘法 * 363 364 >>> (95).__mul__(10) 365 """ 366 pass 367 368 def __neg__(self, *args, **kwargs): # real signature unknown 369 """ -self """ 370 """ 371 将正数变为负数,将负数变为正数 372 373 >>> (95).__neg__() 374 -95 375 >>> (-95).__neg__() 376 """ 377 pass 378 379 @staticmethod # known case of __new__ 380 def __new__(*args, **kwargs): # real signature unknown 381 """ Create and return a new object. See help(type) for accurate signature. """ 382 pass 383 384 def __ne__(self, *args, **kwargs): # real signature unknown 385 """ Return self!=value. """ 386 """ 387 不等于 388 389 >>> (95).__ne__(9) 390 True 391 >>> (95).__ne__(95) 392 False 393 """ 394 pass 395 396 def __or__(self, *args, **kwargs): # real signature unknown 397 """ Return self|value. """ 398 """ 399 二进制或的关系,只要有一个为真,就为真 400 401 >>> a = 4 402 >>> b = 0 403 >>> a.__or__(b) # a --> 00000100 b --> 00000000 404 >>> b = 1 # b --> 00000001 405 >>> a.__or__(b) 406 """ 407 pass 408 409 def __pos__(self, *args, **kwargs): # real signature unknown 410 """ +self """ 411 pass 412 413 def __pow__(self, *args, **kwargs): # real signature unknown 414 """ Return pow(self, value, mod). """ 415 """ 416 幂 417 418 >>> (2).__pow__(10) 419 """ 420 pass 421 422 def __radd__(self, *args, **kwargs): # real signatre unknown 423 """ Return value+self. """ 424 """ 425 加法,将value放在前面 426 427 >>> a.__radd__(b) # 相当于 b+a 428 """ 429 pass 430 431 def __rand__(self, *args, **kwargs): # real signature unknown 432 """ Return value&self. """ 433 """ 434 二进制与的关系,两个都为真,才为真,有一个为假,就为假 435 """ 436 pass 437 438 def __rdivmod__(self, *args, **kwargs): # real signature unknown 439 """ Return divmod(value, self). """ 440 pass 441 442 def __repr__(self, *args, **kwargs): # real signature unknown 443 """ Return repr(self). """ 444 pass 445 446 def __rfloordiv__(self, *args, **kwargs): # real signature unknown 447 """ Return value//self. """ 448 pass 449 450 def __rlshift__(self, *args, **kwargs): # real signature unknown 451 """ Return value<<self. """ 452 pass 453 454 def __rmod__(self, *args, **kwargs): # real signature unknown 455 """ Return value%self. """ 456 pass 457 458 def __rmul__(self, *args, **kwargs): # real signature unknown 459 """ Return value*self. """ 460 pass 461 462 def __ror__(self, *args, **kwargs): # real signature unknown 463 """ Return value|self. """ 464 pass 465 466 def __round__(self, *args, **kwargs): # real signature unknown 467 """ 468 Rounding an Integral returns itself. 469 Rounding with an ndigits argument also returns an integer. 470 """ 471 pass 472 473 def __rpow__(self, *args, **kwargs): # real signature unknown 474 """ Return pow(value, self, mod). """ 475 pass 476 477 def __rrshift__(self, *args, **kwargs): # real signature unknown 478 """ Return value>>self. """ 479 pass 480 481 def __rshift__(self, *args, **kwargs): # real signature unknown 482 """ Return self>>value. """ 483 pass 484 485 def __rsub__(self, *args, **kwargs): # real signature unknown 486 """ Return value-self. """ 487 pass 488 489 def __rtruediv__(self, *args, **kwargs): # real signature unknown 490 """ Return value/self. """ 491 pass 492 493 def __rxor__(self, *args, **kwargs): # real signature unknown 494 """ Return value^self. """ 495 pass 496 497 def __sizeof__(self, *args, **kwargs): # real signature unknown 498 """ Returns size in memory, in bytes """ 499 """ 500 在内存中占多少个字节 501 502 >>> a = 95 503 >>> a.__sizeof__() 504 """ 505 pass 506 507 def __str__(self, *args, **kwargs): # real signature unknown 508 """ Return str(self). """ 509 """ 510 将一个正数转为字符串 511 512 >>> a = 95 513 >>> a = a.__str__() 514 >>> print(type(a)) 515 <class ‘str‘> 516 """ 517 pass 518 519 def __sub__(self, *args, **kwargs): # real signature unknown 520 """ Return self-value. """ 521 """ 522 减法运算 523 524 >>> (95).__sub__(5) 525 """ 526 pass 527 528 def __truediv__(self, *args, **kwargs): # real signature unknown 529 """ Return self/value. """ 530 """ 531 除法运算 532 533 >>> (95).__truediv__(5) 534 19.0 535 """ 536 pass 537 538 def __trunc__(self, *args, **kwargs): # real signature unknown 539 """ Truncating an Integral returns itself. """ 540 """ 541 返回一个对象的整数部分 542 543 >>> (95.95).__trunc__() 544 """ 545 pass 546 def __xor__(self, *args, **kwargs): # real signature unknown 547 """ Return self^value. """ 548 """ 549 将对象与值进行二进制的或运算,一个为真,就为真 550 551 >>> a = 4 552 >>> b = 1 553 >>> a.__xor__(b) 554 >>> c = 0 555 >>> a.__xor__(c) 556 """ 557 558 pass 559 560 denominator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 561 """ 分母 = 1 """ 562 """the denominator of a rational number in lowest terms""" 563 564 imag = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 565 """ 虚数 """ 566 """the imaginary part of a complex number""" 567 568 numerator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 569 """ 分子 = 数字大小 """ 570 """the numerator of a rational number in lowest terms""" 571 572 real = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 573 """ 实属 """ 574 """the real part of a complex number""" 575 576 int
2、布尔值
3、字符串
1 class str(object): 2 """ 3 str(object=‘‘) -> str 4 str(bytes_or_buffer[, encoding[, errors]]) -> str 5 6 Create a new string object from the given object. If encoding or 7 errors is specified, then the object must expose a data buffer 8 that will be decoded using the given encoding and error handler. 9 Otherwise, returns the result of object.__str__() (if defined) 10 or repr(object). 11 encoding defaults to sys.getdefaultencoding(). 12 errors defaults to ‘strict‘. 13 """ 14 def capitalize(self): # real signature unknown; restored from __doc__ 15 """ 16 首字母变大写 17 name = "ocean" 18 a = name.capitalize() 19 print(a) 20 """ 21 S.capitalize() -> str 22 23 Return a capitalized version of S, i.e. make the first character 24 have upper case and the rest lower case. 25 """ 26 return "" 27 28 def casefold(self): # real signature unknown; restored from __doc__ 29 """ 30 首字母变小写 31 name = "Ocean" 32 a =name.casefold() 33 print(a) 34 """ 35 S.casefold() -> str 36 37 Return a version of S suitable for caseless comparisons. 38 """ 39 return "" 40 41 def center(self, width, fillchar=None): # real signature unknown; restored from __doc__ 42 """ 43 内容居中,width:总长度;fillchar:空白处填充内容,默认无。 44 name = "ocean" 45 a = name.center(60,‘$‘) 46 print(a) 47 """ 48 S.center(width[, fillchar]) -> str 49 Return S centered in a string of length width. Padding is 50 done using the specified fill character (default is a space) 51 """ 52 return "" 53 54 def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ 55 """ 56 子序列个数,0到12中a出现了几次。 57 name = "ocean is a good man" 58 v= name.count("a",0,12) 59 print(v) 60 """ 61 S.count(sub[, start[, end]]) -> int 62 63 Return the number of non-overlapping occurrences of substring sub in 64 string S[start:end]. Optional arguments start and end are 65 interpreted as in slice notation. 66 """ 67 return 0 68 69 def encode(self, encoding=‘utf-8‘, errors=‘strict‘): # real signature unknown; restored from __doc__ 70 """ 71 """ 72 编码,针对unicode. 73 temp = "烧饼 74 temp.encode("unicode") 75 """ 76 S.encode(encoding=‘utf-8‘, errors=‘strict‘) -> bytes 77 78 Encode S using the codec registered for encoding. Default encoding 79 is ‘utf-8‘. errors may be given to set a different error 80 handling scheme. Default is ‘strict‘ meaning that encoding errors raise 81 a UnicodeEncodeError. Other possible values are ‘ignore‘, ‘replace‘ and 82 ‘xmlcharrefreplace‘ as well as any other name registered with 83 codecs.register_error that can handle UnicodeEncodeErrors. 84 """ 85 return b"" 86 87 def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__ 88 """ 89 """ 90 是否以XX结束,0到4是否以n结尾 91 name = "ocean is a good man" 92 v = name.endswith("n",0,4) 93 print(v) 94 """ 95 S.endswith(suffix[, start[, end]]) -> bool 96 97 Return True if S ends with the specified suffix, False otherwise. 98 With optional start, test S beginning at that position. 99 With optional end, stop comparing S at that position. 100 suffix can also be a tuple of strings to try. 101 """ 102 return False 103 104 def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__ 105 """ 106 """ 107 将tab转换成空格,默认一个tab转换成8个空格 108 a = n.expandtabs() 109 b = n.expandtabs(16) 110 print(a) 111 print(b) 112 """ 113 S.expandtabs(tabsize=8) -> str 114 115 Return a copy of S where all tab characters are expanded using spaces. 116 If tabsize is not given, a tab size of 8 characters is assumed. 117 """ 118 return "" 119 120 def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ 121 """ 122 """ 123 寻找子序列位置,如果没找到,返回 -1。 124 name = "ocean is a good man" 125 a = name.find("good") 126 print(a) 127 """ 128 S.find(sub[, start[, end]]) -> int 129 130 Return the lowest index in S where substring sub is found, 131 such that sub is contained within S[start:end]. Optional 132 arguments start and end are interpreted as in slice notation. 133 134 Return -1 on failure. 135 """ 136 return 0 137 138 def format(self, *args, **kwargs): # known special case of str.format 139 """ 140 """ 141 字符串格式化,动态参数 142 格式化,传入的值 {"name": ‘alex‘, "a": 19} 143 test = ‘i am {name}, age {a}‘ 144 v1 = test.format(name=‘df‘,a=10) 145 v2 = test.format_map({"name": ‘alex‘, "a": 19}) 146 """ 147 S.format(*args, **kwargs) -> str 148 149 Return a formatted version of S, using substitutions from args and kwargs. 150 The substitutions are identified by braces (‘{‘ and ‘}‘). 151 """ 152 # 格式化,传入的值 {"name": ‘alex‘, "a": 19} 153 # test = ‘i am {name}, age {a}‘ 154 # v1 = test.format(name=‘df‘,a=10) 155 # v2 = test.format_map({"name": ‘alex‘, "a": 19}) 156 """ 157 """ 158 dict = {‘Foo‘: 54.23345} 159 fmt = "Foo = {Foo:.3f}" 160 result = fmt.format_map(dict) 161 print(result) #Foo = 54.233 162 """ 163 S.format_map(mapping) -> str 164 165 Return a formatted version of S, using substitutions from mapping. 166 The substitutions are identified by braces (‘{‘ and ‘}‘). 167 """ 168 return "" 169 170 def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ 171 """ 172 """ 173 #子序列位置,如果没有找到就报错 174 name = "ocean is a good man" 175 a = name.index("ocean") 176 print(a) 177 """ 178 S.index(sub[, start[, end]]) -> int 179 180 Like S.find() but raise ValueError when the substring is not found. 181 """ 182 return 0 183 184 def isalnum(self): # real signature unknown; restored from __doc__ 185 """ 186 """ 187 是否是字母和数字 188 name = "ocean is a good man" 189 a = name.isalnum() 190 print(a) 191 """ 192 S.isalnum() -> bool 193 194 Return True if all characters in S are alphanumeric 195 and there is at least one character in S, False otherwise. 196 """ 197 return False 198 199 def isalpha(self): # real signature unknown; restored from __doc__ 200 """ 201 """ 202 是否是字母 203 name = "ocean is a good man" 204 a = name.isalpha() 205 print(a) 206 """ 207 S.isalpha() -> bool 208 209 Return True if all characters in S are alphabetic 210 and there is at least one character in S, False otherwise. 211 """ 212 return False 213 214 def isdecimal(self): # real signature unknown; restored from __doc__ 215 """ 216 检查字符串是否只包含十进制字符。这种方法只存在于unicode对象。 217 """ 218 S.isdecimal() -> bool 219 220 Return True if there are only decimal characters in S, 221 False otherwise. 222 """ 223 return False 224 225 def isdigit(self): # real signature unknown; restored from __doc__ 226 """ 227 """ 228 是否是数字 229 name = "ocean is a good man" 230 a = name.isdigit() 231 print(a) 232 """ 233 S.isdigit() -> bool 234 235 Return True if all characters in S are digits 236 and there is at least one character in S, False otherwise. 237 """ 238 return False 239 240 def isidentifier(self): # real signature unknown; restored from __doc__ 241 """ 242 """ 243 判断字符串是否可为合法的标识符 244 """ 245 S.isidentifier() -> bool 246 247 Return True if S is a valid identifier according 248 to the language definition. 249 250 Use keyword.iskeyword() to test for reserved identifiers 251 such as "def" and "class". 252 """ 253 return False 254 255 def islower(self): # real signature unknown; restored from __doc__ 256 """ 257 """ 258 是否小写 259 name = "ocean is A good man" 260 a = name.islower() 261 print(a) 262 """ 263 S.islower() -> bool 264 265 Return True if all cased characters in S are lowercase and there is 266 at least one cased character in S, False otherwise. 267 """ 268 return False 269 270 def isnumeric(self): # real signature unknown; restored from __doc__ 271 """ 272 """ 273 检查是否只有数字字符组成的字符串 274 name = "111111111111111” 275 a = name.isnumeric() 276 print(a) 277 """ 278 S.isnumeric() -> bool 279 280 Return True if there are only numeric characters in S, 281 False otherwise. 282 """ 283 return False 284 285 def isprintable(self): # real signature unknown; restored from __doc__ 286 """ 287 """ 288 判断字符串中所有字符是否都属于可见字符 289 name = "ocean is a good man" 290 a = name.isprintable() 291 print(a) 292 """ 293 S.isprintable() -> bool 294 295 Return True if all characters in S are considered 296 printable in repr() or S is empty, False otherwise. 297 """ 298 return False 299 300 def isspace(self): # real signature unknown; restored from __doc__ 301 """ 302 """ 303 字符串是否只由空格组成 304 name = " " 305 a = name.isspace() 306 print(a) 307 """ 308 S.isspace() -> bool 309 310 Return True if all characters in S are whitespace 311 and there is at least one character in S, False otherwise. 312 """ 313 return False 314 315 def istitle(self): # real signature unknown; restored from __doc__ 316 """ 317 """ 318 检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写 319 name = "Ocean Is A Good Man" 320 a = name.istitle() 321 print(a) 322 """ 323 """ 324 S.istitle() -> bool 325 326 Return True if S is a titlecased string and there is at least one 327 character in S, i.e. upper- and titlecase characters may only 328 follow uncased characters and lowercase characters only cased ones. 329 Return False otherwise. 330 """ 331 return False 332 333 def isupper(self): # real signature unknown; restored from __doc__ 334 """ 335 """ 336 检测字符串中所有的字母是否都为大写 337 name = "OCEAN" 338 a = name.isupper() 339 print(a) 340 """ 341 S.isupper() -> bool 342 343 Return True if all cased characters in S are uppercase and there is 344 at least one cased character in S, False otherwise. 345 """ 346 return False 347 348 def join(self, iterable): # real signature unknown; restored from __doc__ 349 """ 350 """ 351 连接两个字符串 352 li = ["ocean","handsome"] 353 a = "".join(li) 354 b = "_".join(li) 355 print(a) 356 print(b) 357 """ 358 S.join(iterable) -> str 359 360 Return a string which is the concatenation of the strings in the 361 iterable. The separator between elements is S. 362 """ 363 return "" 364 365 def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__ 366 """ 367 """ 368 向左对齐,右侧填充 369 name = "ocean is a good man" 370 a = name.ljust(60,$) 371 print(a) 372 """ 373 S.ljust(width[, fillchar]) -> str 374 375 Return S left-justified in a Unicode string of length width. Padding is 376 done using the specified fill character (default is a space). 377 """ 378 return "" 379 380 def lower(self): # real signature unknown; restored from __doc__ 381 """ 382 """ 383 容左对齐,右侧填充 384 name = "NiNi" 385 a = name.lower() 386 print(a) 387 """ 388 S.lower() -> str 389 390 Return a copy of the string S converted to lowercase. 391 """ 392 return "" 393 394 def lstrip(self, chars=None): # real signature unknown; restored from __doc__ 395 """ 396 """ 移除左侧空白 """ 397 S.lstrip([chars]) -> str 398 399 Return a copy of the string S with leading whitespace removed. 400 If chars is given and not None, remove characters in chars instead. 401 """ 402 return "" 403 404 def maketrans(self, *args, **kwargs): # real signature unknown 405 """ 406 """ 407 用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。 408 from string import maketrans 409 intab = "aeiou" 410 outtab = "12345" 411 trantab = maketrans(intab, outtab) 412 str = "this is string example....wow!!!"; 413 print str.translate(trantab); 414 """ 415 Return a translation table usable for str.translate(). 416 417 If there is only one argument, it must be a dictionary mapping Unicode 418 ordinals (integers) or characters to Unicode ordinals, strings or None. 419 Character keys will be then converted to ordinals. 420 If there are two arguments, they must be strings of equal length, and 421 in the resulting dictionary, each character in x will be mapped to the 422 character at the same position in y. If there is a third argument, it 423 must be a string, whose characters will be mapped to None in the result. 424 """ 425 pass 426 427 def partition(self, sep): # real signature unknown; restored from __doc__ 428 """ 429 """ 430 分割,前,中,后三部分 431 name = "ocean is a good man" 432 a = name.partition("good") 433 print(a) 434 """ 435 S.partition(sep) -> (head, sep, tail) 436 437 Search for the separator sep in S, and return the part before it, 438 the separator itself, and the part after it. If the separator is not 439 found, return S and two empty strings. 440 """ 441 pass 442 443 def replace(self, old, new, count=None): # real signature unknown; restored from __doc__ 444 """ 445 """ 446 替换 447 name = "ocean is a good man" 448 a = name.replace("good","man") 449 print(a) 450 """ 451 S.replace(old, new[, count]) -> str 452 453 Return a copy of S with all occurrences of substring 454 old replaced by new. If the optional argument count is 455 given, only the first count occurrences are replaced. 456 """ 457 return "" 458 459 def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ 460 """ 461 """ 462 返回字符串最后一次出现的位置,如果没有匹配项则返回-1 463 """ 464 S.rfind(sub[, start[, end]]) -> int 465 466 Return the highest index in S where substring sub is found, 467 such that sub is contained within S[start:end]. Optional 468 arguments start and end are interpreted as in slice notation. 469 470 Return -1 on failure. 471 """ 472 return 0 473 474 def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ 475 """ 476 """ 477 返回子字符串 str 在字符串中最后出现的位置,如果没有匹配的字符串会报异常 478 """ 479 S.rindex(sub[, start[, end]]) -> int 480 481 Like S.rfind() but raise ValueError when the substring is not found. 482 """ 483 return 0 484 485 def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__ 486 """ 487 """ 488 返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串 489 str = "this is string example....wow!!!" 490 print(str.rjust(50, ‘$‘)) 491 """ 492 S.rjust(width[, fillchar]) -> str 493 494 Return S right-justified in a string of length width. Padding is 495 done using the specified fill character (default is a space). 496 """ 497 return "" 498 499 def rpartition(self, sep): # real signature unknown; restored from __doc__ 500 """ 501 """ 502 根据指定的分隔符将字符串进行分割 503 """ 504 S.rpartition(sep) -> (head, sep, tail) 505 506 Search for the separator sep in S, starting at the end of S, and return 507 the part before it, the separator itself, and the part after it. If the 508 separator is not found, return two empty strings and S. 509 """ 510 pass 511 512 def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__ 513 """ 514 """ 515 指定分隔符对字符串进行切片 516 name = "ocean is a good man" 517 a = name.rsplit("is") 518 print(a) 519 """ 520 S.rsplit(sep=None, maxsplit=-1) -> list of strings 521 522 Return a list of the words in S, using sep as the 523 delimiter string, starting at the end of the string and 524 working to the front. If maxsplit is given, at most maxsplit 525 splits are done. If sep is not specified, any whitespace string 526 is a separator. 527 """ 528 return [] 529 530 def rstrip(self, chars=None): # real signature unknown; restored from __doc__ 531 """ 532 """ 533 删除 string 字符串末尾的指定字符(默认为空格) 534 """ 535 S.rstrip([chars]) -> str 536 537 Return a copy of the string S with trailing whitespace removed. 538 If chars is given and not None, remove characters in chars instead. 539 """ 540 return "" 541 542 def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__ 543 """ 544 """ 545 通过指定分隔符对字符串进行切片 546 str = "Line1-abcdef \nLine2-abc \nLine4-abcd"; 547 print str.split( ); 548 print str.split(‘ ‘, 1 ); 549 """ 550 S.split(sep=None, maxsplit=-1) -> list of strings 551 552 Return a list of the words in S, using sep as the 553 delimiter string. If maxsplit is given, at most maxsplit 554 splits are done. If sep is not specified or is None, any 555 whitespace string is a separator and empty strings are 556 removed from the result. 557 """ 558 return [] 559 560 def splitlines(self, keepends=None): # real signature unknown; restored from __doc__ 561 """ 562 """ 563 按照行分隔,返回一个包含各行作为元素的列表 564 """ 565 S.splitlines([keepends]) -> list of strings 566 567 Return a list of the lines in S, breaking at line boundaries. 568 Line breaks are not included in the resulting list unless keepends 569 is given and true. 570 """ 571 return [] 572 573 def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__ 574 """ 575 """ 576 检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False 577 """ 578 S.startswith(prefix[, start[, end]]) -> bool 579 580 Return True if S starts with the specified prefix, False otherwise. 581 With optional start, test S beginning at that position. 582 With optional end, stop comparing S at that position. 583 prefix can also be a tuple of strings to try. 584 """ 585 return False 586 587 def strip(self, chars=None): # real signature unknown; restored from __doc__ 588 """ 589 """ 590 用于移除字符串头尾指定的字符(默认为空格). 591 """ 592 S.strip([chars]) -> str 593 594 Return a copy of the string S with leading and trailing 595 whitespace removed. 596 If chars is given and not None, remove characters in chars instead. 597 """ 598 return "" 599 600 def swapcase(self): # real signature unknown; restored from __doc__ 601 """ 602 """ 603 用于对字符串的大小写字母进行转换 604 """ 605 S.swapcase() -> str 606 607 Return a copy of S with uppercase characters converted to lowercase 608 and vice versa. 609 """ 610 return "" 611 612 def title(self): # real signature unknown; restored from __doc__ 613 """ 614 S.title() -> str 615 616 Return a titlecased version of S, i.e. words start with title case 617 characters, all remaining cased characters have lower case. 618 """ 619 return "" 620 621 def translate(self, table): # real signature unknown; restored from __doc__ 622 """ 623 S.translate(table) -> str 624 625 Return a copy of the string S in which each character has been mapped 626 through the given translation table. The table must implement 627 lookup/indexing via __getitem__, for instance a dictionary or list, 628 mapping Unicode ordinals to Unicode ordinals, strings, or None. If 629 this operation raises LookupError, the character is left untouched. 630 Characters mapped to None are deleted. 631 """ 632 return "" 633 634 def upper(self): # real signature unknown; restored from __doc__ 635 """ 636 """ 637 将字符串中的小写字母转为大写字母 638 """ 639 S.upper() -> str 640 641 Return a copy of S converted to uppercase. 642 """ 643 return "" 644 645 def zfill(self, width): # real signature unknown; restored from __doc__ 646 """ 647 """ 648 返回指定长度的字符串,原字符串右对齐,前面填充0 649 """ 650 S.zfill(width) -> str 651 652 Pad a numeric string S with zeros on the left, to fill a field 653 of the specified width. The string S is never truncated. 654 """ 655 return "" 656 657 def __add__(self, *args, **kwargs): # real signature unknown 658 """ Return self+value. """ 659 pass 660 661 def __contains__(self, *args, **kwargs): # real signature unknown 662 """ Return key in self. """ 663 pass 664 665 def __eq__(self, *args, **kwargs): # real signature unknown 666 """ Return self==value. """ 667 pass 668 669 def __format__(self, format_spec): # real signature unknown; restored from __doc__ 670 """ 671 S.__format__(format_spec) -> str 672 673 Return a formatted version of S as described by format_spec. 674 """ 675 return "" 676 677 def __getattribute__(self, *args, **kwargs): # real signature unknown 678 """ Return getattr(self, name). """ 679 pass 680 681 def __getitem__(self, *args, **kwargs): # real signature unknown 682 """ Return self[key]. """ 683 pass 684 685 def __getnewargs__(self, *args, **kwargs): # real signature unknown 686 pass 687 688 def __ge__(self, *args, **kwargs): # real signature unknown 689 """ Return self>=value. """ 690 pass 691 692 def __gt__(self, *args, **kwargs): # real signature unknown 693 """ Return self>value. """ 694 pass 695 696 def __hash__(self, *args, **kwargs): # real signature unknown 697 """ Return hash(self). """ 698 pass 699 700 def __init__(self, value=‘‘, encoding=None, errors=‘strict‘): # known special case of str.__init__ 701 """ 702 str(object=‘‘) -> str 703 str(bytes_or_buffer[, encoding[, errors]]) -> str 704 705 Create a new string object from the given object. If encoding or 706 errors is specified, then the object must expose a data buffer 707 that will be decoded using the given encoding and error handler. 708 Otherwise, returns the result of object.__str__() (if defined) 709 or repr(object). 710 encoding defaults to sys.getdefaultencoding(). 711 errors defaults to ‘strict‘. 712 # (copied from class doc) 713 """ 714 pass 715 716 def __iter__(self, *args, **kwargs): # real signature unknown 717 """ Implement iter(self). """ 718 pass 719 720 def __len__(self, *args, **kwargs): # real signature unknown 721 """ Return len(self). """ 722 pass 723 724 def __le__(self, *args, **kwargs): # real signature unknown 725 """ Return self<=value. """ 726 pass 727 728 def __lt__(self, *args, **kwargs): # real signature unknown 729 """ Return self<value. """ 730 pass 731 732 def __mod__(self, *args, **kwargs): # real signature unknown 733 """ Return self%value. """ 734 pass 735 736 def __mul__(self, *args, **kwargs): # real signature unknown 737 """ Return self*value.n """ 738 pass 739 740 @staticmethod # known case of __new__ 741 def __new__(*args, **kwargs): # real signature unknown 742 """ Create and return a new object. See help(type) for accurate signature. """ 743 pass 744 745 def __ne__(self, *args, **kwargs): # real signature unknown 746 """ Return self!=value. """ 747 pass 748 749 def __repr__(self, *args, **kwargs): # real signature unknown 750 """ Return repr(self). """ 751 pass 752 753 def __rmod__(self, *args, **kwargs): # real signature unknown 754 """ Return value%self. """ 755 pass 756 757 def __rmul__(self, *args, **kwargs): # real signature unknown 758 """ Return self*value. """ 759 pass 760 761 def __sizeof__(self): # real signature unknown; restored from __doc__ 762 """ S.__sizeof__() -> size of S in memory, in bytes """ 763 pass 764 765 def __str__(self, *args, **kwargs): # real signature unknown 766 """ Return str(self). """ 767 pass 768 769 770 str
4、列表
5、元组(不可修改)
6、字典(无序)
1、编码与进制转换
标签:bool lex set cal err format nec any mod
原文地址:http://www.cnblogs.com/douhaiyang/p/6091479.html