python学习——基本数据类型
一、运算符
1.算术运算:
2.比较运算
3.赋值运算
4.逻辑运算
5.成员运算
二、基本数据类型
1.数字
1.1 整形数字和长整形数字:在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647,在64位系统上,整数的位数为64位,取值范围为-2**63~2**63-1,即-9223372036854775808~9223372036854775807
1.2 有关number模块代码如下所示:
1 class Number(metaclass=ABCMeta): 2 """All numbers inherit from this class. 3 4 If you just want to check if an argument x is a number, without 5 caring what kind, use isinstance(x, Number). 6 """ 7 __slots__ = () 8 9 # Concrete numeric types must provide their own hash implementation 10 __hash__ = None 11 12 13 ## Notes on Decimal 14 ## ---------------- 15 ## Decimal has all of the methods specified by the Real abc, but it should 16 ## not be registered as a Real because decimals do not interoperate with 17 ## binary floats (i.e. Decimal('3.14') + 2.71828 is undefined). But, 18 ## abstract reals are expected to interoperate (i.e. R1 + R2 should be 19 ## expected to work if R1 and R2 are both Reals). 20 21 class Complex(Number): 22 """Complex defines the operations that work on the builtin complex type. 23 24 In short, those are: a conversion to complex, .real, .imag, +, -, 25 *, /, abs(), .conjugate, ==, and !=. 26 27 If it is given heterogeneous arguments, and doesn't have special 28 knowledge about them, it should fall back to the builtin complex 29 type as described below. 30 """ 31 32 __slots__ = () 33 34 @abstractmethod 35 def __complex__(self): 36 """Return a builtin complex instance. Called for complex(self).""" 37 38 def __bool__(self): 39 """True if self != 0. Called for bool(self).""" 40 return self != 0 41 42 @property 43 @abstractmethod 44 def real(self): 45 """Retrieve the real component of this number. 46 47 This should subclass Real. 48 """ 49 raise NotImplementedError 50 51 @property 52 @abstractmethod 53 def imag(self): 54 """Retrieve the imaginary component of this number. 55 56 This should subclass Real. 57 """ 58 raise NotImplementedError 59 60 @abstractmethod 61 def __add__(self, other): 62 """self + other""" 63 raise NotImplementedError 64 65 @abstractmethod 66 def __radd__(self, other): 67 """other + self""" 68 raise NotImplementedError 69 70 @abstractmethod 71 def __neg__(self): 72 """-self""" 73 raise NotImplementedError 74 75 @abstractmethod 76 def __pos__(self): 77 """+self""" 78 raise NotImplementedError 79 80 def __sub__(self, other): 81 """self - other""" 82 return self + -other 83 84 def __rsub__(self, other): 85 """other - self""" 86 return -self + other 87 88 @abstractmethod 89 def __mul__(self, other): 90 """self * other""" 91 raise NotImplementedError 92 93 @abstractmethod 94 def __rmul__(self, other): 95 """other * self""" 96 raise NotImplementedError 97 98 @abstractmethod 99 def __truediv__(self, other): 100 """self / other: Should promote to float when necessary.""" 101 raise NotImplementedError 102 103 @abstractmethod 104 def __rtruediv__(self, other): 105 """other / self""" 106 raise NotImplementedError 107 108 @abstractmethod 109 def __pow__(self, exponent): 110 """self**exponent; should promote to float or complex when necessary.""" 111 raise NotImplementedError 112 113 @abstractmethod 114 def __rpow__(self, base): 115 """base ** self""" 116 raise NotImplementedError 117 118 @abstractmethod 119 def __abs__(self): 120 """Returns the Real distance from 0. Called for abs(self).""" 121 raise NotImplementedError 122 123 @abstractmethod 124 def conjugate(self): 125 """(x+y*i).conjugate() returns (x-y*i).""" 126 raise NotImplementedError 127 128 @abstractmethod 129 def __eq__(self, other): 130 """self == other""" 131 raise NotImplementedError 132 133 Complex.register(complex) 134 135 136 class Real(Complex): 137 """To Complex, Real adds the operations that work on real numbers. 138 139 In short, those are: a conversion to float, trunc(), divmod, 140 %, <, <=, >, and >=. 141 142 Real also provides defaults for the derived operations. 143 """ 144 145 __slots__ = () 146 147 @abstractmethod 148 def __float__(self): 149 """Any Real can be converted to a native float object. 150 151 Called for float(self).""" 152 raise NotImplementedError 153 154 @abstractmethod 155 def __trunc__(self): 156 """trunc(self): Truncates self to an Integral. 157 158 Returns an Integral i such that: 159 * i>0 iff self>0; 160 * abs(i) <= abs(self); 161 * for any Integral j satisfying the first two conditions, 162 abs(i) >= abs(j) [i.e. i has "maximal" abs among those]. 163 i.e. "truncate towards 0". 164 """ 165 raise NotImplementedError 166 167 @abstractmethod 168 def __floor__(self): 169 """Finds the greatest Integral <= self.""" 170 raise NotImplementedError 171 172 @abstractmethod 173 def __ceil__(self): 174 """Finds the least Integral >= self.""" 175 raise NotImplementedError 176 177 @abstractmethod 178 def __round__(self, ndigits=None): 179 """Rounds self to ndigits decimal places, defaulting to 0. 180 181 If ndigits is omitted or None, returns an Integral, otherwise 182 returns a Real. Rounds half toward even. 183 """ 184 raise NotImplementedError 185 186 def __divmod__(self, other): 187 """divmod(self, other): The pair (self // other, self % other). 188 189 Sometimes this can be computed faster than the pair of 190 operations. 191 """ 192 return (self // other, self % other) 193 194 def __rdivmod__(self, other): 195 """divmod(other, self): The pair (self // other, self % other). 196 197 Sometimes this can be computed faster than the pair of 198 operations. 199 """ 200 return (other // self, other % self) 201 202 @abstractmethod 203 def __floordiv__(self, other): 204 """self // other: The floor() of self/other.""" 205 raise NotImplementedError 206 207 @abstractmethod 208 def __rfloordiv__(self, other): 209 """other // self: The floor() of other/self.""" 210 raise NotImplementedError 211 212 @abstractmethod 213 def __mod__(self, other): 214 """self % other""" 215 raise NotImplementedError 216 217 @abstractmethod 218 def __rmod__(self, other): 219 """other % self""" 220 raise NotImplementedError 221 222 @abstractmethod 223 def __lt__(self, other): 224 """self < other 225 226 < on Reals defines a total ordering, except perhaps for NaN.""" 227 raise NotImplementedError 228 229 @abstractmethod 230 def __le__(self, other): 231 """self <= other""" 232 raise NotImplementedError 233 234 # Concrete implementations of Complex abstract methods. 235 def __complex__(self): 236 """complex(self) == complex(float(self), 0)""" 237 return complex(float(self)) 238 239 @property 240 def real(self): 241 """Real numbers are their real component.""" 242 return +self 243 244 @property 245 def imag(self): 246 """Real numbers have no imaginary component.""" 247 return 0 248 249 def conjugate(self): 250 """Conjugate is a no-op for Reals.""" 251 return +self 252 253 Real.register(float) 254 255 256 class Rational(Real): 257 """.numerator and .denominator should be in lowest terms.""" 258 259 __slots__ = () 260 261 @property 262 @abstractmethod 263 def numerator(self): 264 raise NotImplementedError 265 266 @property 267 @abstractmethod 268 def denominator(self): 269 raise NotImplementedError 270 271 # Concrete implementation of Real's conversion to float. 272 def __float__(self): 273 """float(self) = self.numerator / self.denominator 274 275 It's important that this conversion use the integer's "true" 276 division rather than casting one side to float before dividing 277 so that ratios of huge integers convert without overflowing. 278 279 """ 280 return self.numerator / self.denominator 281 282 283 class Integral(Rational): 284 """Integral adds a conversion to int and the bit-string operations.""" 285 286 __slots__ = () 287 288 @abstractmethod 289 def __int__(self): 290 """int(self)""" 291 raise NotImplementedError 292 293 def __index__(self): 294 """Called whenever an index is needed, such as in slicing""" 295 return int(self) 296 297 @abstractmethod 298 def __pow__(self, exponent, modulus=None): 299 """self ** exponent % modulus, but maybe faster. 300 301 Accept the modulus argument if you want to support the 302 3-argument version of pow(). Raise a TypeError if exponent < 0 303 or any argument isn't Integral. Otherwise, just implement the 304 2-argument version described in Complex. 305 """ 306 raise NotImplementedError 307 308 @abstractmethod 309 def __lshift__(self, other): 310 """self << other""" 311 raise NotImplementedError 312 313 @abstractmethod 314 def __rlshift__(self, other): 315 """other << self""" 316 raise NotImplementedError 317 318 @abstractmethod 319 def __rshift__(self, other): 320 """self >> other""" 321 raise NotImplementedError 322 323 @abstractmethod 324 def __rrshift__(self, other): 325 """other >> self""" 326 raise NotImplementedError 327 328 @abstractmethod 329 def __and__(self, other): 330 """self & other""" 331 raise NotImplementedError 332 333 @abstractmethod 334 def __rand__(self, other): 335 """other & self""" 336 raise NotImplementedError 337 338 @abstractmethod 339 def __xor__(self, other): 340 """self ^ other""" 341 raise NotImplementedError 342 343 @abstractmethod 344 def __rxor__(self, other): 345 """other ^ self""" 346 raise NotImplementedError 347 348 @abstractmethod 349 def __or__(self, other): 350 """self | other""" 351 raise NotImplementedError 352 353 @abstractmethod 354 def __ror__(self, other): 355 """other | self""" 356 raise NotImplementedError 357 358 @abstractmethod 359 def __invert__(self): 360 """~self""" 361 raise NotImplementedError 362 363 # Concrete implementations of Rational and Real abstract methods. 364 def __float__(self): 365 """float(self) == float(int(self))""" 366 return float(int(self)) 367 368 @property 369 def numerator(self): 370 """Integers are their own numerators.""" 371 return +self 372 373 @property 374 def denominator(self): 375 """Integers have a denominator of 1.""" 376 return 1
2.布尔值
2.1 真和假(True and False)
2.2 0 和 1分别代表假和真
2.3 有关布尔值是假有以下几种情况(返回 False,其他的布尔值都为真,返回 True)
( None 0 ''''空字符串 ()空元组 {}空字典 []空列表 等等……(因为可能还有我不知道的))
3.字符串
3.1 字符串的创建(用单引号或者双引号引起来的就叫字符串)
1 str1 = 'hello world' 2 str2 = "liulonghai"
3.2 字符串有以下几个常用功能:
移除空白
分割
长度
索引
切片
3.3 字符串的相关代码如下:
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): 9 """ 首字母变大写 """ 10 """ 11 S.capitalize() -> string 12 13 Return a copy of the string S with only its first character 14 capitalized. 15 """ 16 return "" 17 18 def center(self, width, fillchar=None): 19 """ 内容居中,width:总长度;fillchar:空白处填充内容,默认无 """ 20 """ 21 S.center(width[, fillchar]) -> string 22 23 Return S centered in a string of length width. Padding is 24 done using the specified fill character (default is a space) 25 """ 26 return "" 27 28 def count(self, sub, start=None, end=None): 29 """ 子序列个数 """ 30 """ 31 S.count(sub[, start[, end]]) -> int 32 33 Return the number of non-overlapping occurrences of substring sub in 34 string S[start:end]. Optional arguments start and end are interpreted 35 as in slice notation. 36 """ 37 return 0 38 39 def decode(self, encoding=None, errors=None): 40 """ 解码 """ 41 """ 42 S.decode([encoding[,errors]]) -> object 43 44 Decodes S using the codec registered for encoding. encoding defaults 45 to the default encoding. errors may be given to set a different error 46 handling scheme. Default is 'strict' meaning that encoding errors raise 47 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 48 as well as any other name registered with codecs.register_error that is 49 able to handle UnicodeDecodeErrors. 50 """ 51 return object() 52 53 def encode(self, encoding=None, errors=None): 54 """ 编码,针对unicode """ 55 """ 56 S.encode([encoding[,errors]]) -> object 57 58 Encodes S using the codec registered for encoding. encoding defaults 59 to the default encoding. errors may be given to set a different error 60 handling scheme. Default is 'strict' meaning that encoding errors raise 61 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 62 'xmlcharrefreplace' as well as any other name registered with 63 codecs.register_error that is able to handle UnicodeEncodeErrors. 64 """ 65 return object() 66 67 def endswith(self, suffix, start=None, end=None): 68 """ 是否以 xxx 结束 """ 69 """ 70 S.endswith(suffix[, start[, end]]) -> bool 71 72 Return True if S ends with the specified suffix, False otherwise. 73 With optional start, test S beginning at that position. 74 With optional end, stop comparing S at that position. 75 suffix can also be a tuple of strings to try. 76 """ 77 return False 78 79 def expandtabs(self, tabsize=None): 80 """ 将tab转换成空格,默认一个tab转换成8个空格 """ 81 """ 82 S.expandtabs([tabsize]) -> string 83 84 Return a copy of S where all tab characters are expanded using spaces. 85 If tabsize is not given, a tab size of 8 characters is assumed. 86 """ 87 return "" 88 89 def find(self, sub, start=None, end=None): 90 """ 寻找子序列位置,如果没找到,返回 -1 """ 91 """ 92 S.find(sub [,start [,end]]) -> int 93 94 Return the lowest index in S where substring sub is found, 95 such that sub is contained within S[start:end]. Optional 96 arguments start and end are interpreted as in slice notation. 97 98 Return -1 on failure. 99 """ 100 return 0 101 102 def format(*args, **kwargs): # known special case of str.format 103 """ 字符串格式化,动态参数,将函数式编程时细说 """ 104 """ 105 S.format(*args, **kwargs) -> string 106 107 Return a formatted version of S, using substitutions from args and kwargs. 108 The substitutions are identified by braces ('{' and '}'). 109 """ 110 pass 111 112 def index(self, sub, start=None, end=None): 113 """ 子序列位置,如果没找到,报错 """ 114 S.index(sub [,start [,end]]) -> int 115 116 Like S.find() but raise ValueError when the substring is not found. 117 """ 118 return 0 119 120 def isalnum(self): 121 """ 是否是字母和数字 """ 122 """ 123 S.isalnum() -> bool 124 125 Return True if all characters in S are alphanumeric 126 and there is at least one character in S, False otherwise. 127 """ 128 return False 129 130 def isalpha(self): 131 """ 是否是字母 """ 132 """ 133 S.isalpha() -> bool 134 135 Return True if all characters in S are alphabetic 136 and there is at least one character in S, False otherwise. 137 """ 138 return False 139 140 def isdigit(self): 141 """ 是否是数字 """ 142 """ 143 S.isdigit() -> bool 144 145 Return True if all characters in S are digits 146 and there is at least one character in S, False otherwise. 147 """ 148 return False 149 150 def islower(self): 151 """ 是否小写 """ 152 """ 153 S.islower() -> bool 154 155 Return True if all cased characters in S are lowercase and there is 156 at least one cased character in S, False otherwise. 157 """ 158 return False 159 160 def isspace(self): 161 """ 162 S.isspace() -> bool 163 164 Return True if all characters in S are whitespace 165 and there is at least one character in S, False otherwise. 166 """ 167 return False 168 169 def istitle(self): 170 """ 171 S.istitle() -> bool 172 173 Return True if S is a titlecased string and there is at least one 174 character in S, i.e. uppercase characters may only follow uncased 175 characters and lowercase characters only cased ones. Return False 176 otherwise. 177 """ 178 return False 179 180 def isupper(self): 181 """ 182 S.isupper() -> bool 183 184 Return True if all cased characters in S are uppercase and there is 185 at least one cased character in S, False otherwise. 186 """ 187 return False 188 189 def join(self, iterable): 190 """ 连接 """ 191 """ 192 S.join(iterable) -> string 193 194 Return a string which is the concatenation of the strings in the 195 iterable. The separator between elements is S. 196 """ 197 return "" 198 199 def ljust(self, width, fillchar=None): 200 """ 内容左对齐,右侧填充 """ 201 """ 202 S.ljust(width[, fillchar]) -> string 203 204 Return S left-justified in a string of length width. Padding is 205 done using the specified fill character (default is a space). 206 """ 207 return "" 208 209 def lower(self): 210 """ 变小写 """ 211 """ 212 S.lower() -> string 213 214 Return a copy of the string S converted to lowercase. 215 """ 216 return "" 217 218 def lstrip(self, chars=None): 219 """ 移除左侧空白 """ 220 """ 221 S.lstrip([chars]) -> string or unicode 222 223 Return a copy of the string S with leading whitespace removed. 224 If chars is given and not None, remove characters in chars instead. 225 If chars is unicode, S will be converted to unicode before stripping 226 """ 227 return "" 228 229 def partition(self, sep): 230 """ 分割,前,中,后三部分 """ 231 """ 232 S.partition(sep) -> (head, sep, tail) 233 234 Search for the separator sep in S, and return the part before it, 235 the separator itself, and the part after it. If the separator is not 236 found, return S and two empty strings. 237 """ 238 pass 239 240 def replace(self, old, new, count=None): 241 """ 替换 """ 242 """ 243 S.replace(old, new[, count]) -> string 244 245 Return a copy of string S with all occurrences of substring 246 old replaced by new. If the optional argument count is 247 given, only the first count occurrences are replaced. 248 """ 249 return "" 250 251 def rfind(self, sub, start=None, end=None): 252 """ 253 S.rfind(sub [,start [,end]]) -> int 254 255 Return the highest index in S where substring sub is found, 256 such that sub is contained within S[start:end]. Optional 257 arguments start and end are interpreted as in slice notation. 258 259 Return -1 on failure. 260 """ 261 return 0 262 263 def rindex(self, sub, start=None, end=None): 264 """ 265 S.rindex(sub [,start [,end]]) -> int 266 267 Like S.rfind() but raise ValueError when the substring is not found. 268 """ 269 return 0 270 271 def rjust(self, width, fillchar=None): 272 """ 273 S.rjust(width[, fillchar]) -> string 274 275 Return S right-justified in a string of length width. Padding is 276 done using the specified fill character (default is a space) 277 """ 278 return "" 279 280 def rpartition(self, sep): 281 """ 282 S.rpartition(sep) -> (head, sep, tail) 283 284 Search for the separator sep in S, starting at the end of S, and return 285 the part before it, the separator itself, and the part after it. If the 286 separator is not found, return two empty strings and S. 287 """ 288 pass 289 290 def rsplit(self, sep=None, maxsplit=None): 291 """ 292 S.rsplit([sep [,maxsplit]]) -> list of strings 293 294 Return a list of the words in the string S, using sep as the 295 delimiter string, starting at the end of the string and working 296 to the front. If maxsplit is given, at most maxsplit splits are 297 done. If sep is not specified or is None, any whitespace string 298 is a separator. 299 """ 300 return [] 301 302 def rstrip(self, chars=None): 303 """ 304 S.rstrip([chars]) -> string or unicode 305 306 Return a copy of the string S with trailing whitespace removed. 307 If chars is given and not None, remove characters in chars instead. 308 If chars is unicode, S will be converted to unicode before stripping 309 """ 310 return "" 311 312 def split(self, sep=None, maxsplit=None): 313 """ 分割, maxsplit最多分割几次 """ 314 """ 315 S.split([sep [,maxsplit]]) -> list of strings 316 317 Return a list of the words in the string S, using sep as the 318 delimiter string. If maxsplit is given, at most maxsplit 319 splits are done. If sep is not specified or is None, any 320 whitespace string is a separator and empty strings are removed 321 from the result. 322 """ 323 return [] 324 325 def splitlines(self, keepends=False): 326 """ 根据换行分割 """ 327 """ 328 S.splitlines(keepends=False) -> list of strings 329 330 Return a list of the lines in S, breaking at line boundaries. 331 Line breaks are not included in the resulting list unless keepends 332 is given and true. 333 """ 334 return [] 335 336 def startswith(self, prefix, start=None, end=None): 337 """ 是否起始 """ 338 """ 339 S.startswith(prefix[, start[, end]]) -> bool 340 341 Return True if S starts with the specified prefix, False otherwise. 342 With optional start, test S beginning at that position. 343 With optional end, stop comparing S at that position. 344 prefix can also be a tuple of strings to try. 345 """ 346 return False 347 348 def strip(self, chars=None): 349 """ 移除两段空白 """ 350 """ 351 S.strip([chars]) -> string or unicode 352 353 Return a copy of the string S with leading and trailing 354 whitespace removed. 355 If chars is given and not None, remove characters in chars instead. 356 If chars is unicode, S will be converted to unicode before stripping 357 """ 358 return "" 359 360 def swapcase(self): 361 """ 大写变小写,小写变大写 """ 362 """ 363 S.swapcase() -> string 364 365 Return a copy of the string S with uppercase characters 366 converted to lowercase and vice versa. 367 """ 368 return "" 369 370 def title(self): 371 """ 372 S.title() -> string 373 374 Return a titlecased version of S, i.e. words start with uppercase 375 characters, all remaining cased characters have lowercase. 376 """ 377 return "" 378 379 def translate(self, table, deletechars=None): 380 """ 381 转换,需要先做一个对应表,最后一个表示删除字符集合 382 intab = "aeiou" 383 outtab = "12345" 384 trantab = maketrans(intab, outtab) 385 str = "this is string example....wow!!!" 386 print str.translate(trantab, 'xm') 387 """ 388 389 """ 390 S.translate(table [,deletechars]) -> string 391 392 Return a copy of the string S, where all characters occurring 393 in the optional argument deletechars are removed, and the 394 remaining characters have been mapped through the given 395 translation table, which must be a string of length 256 or None. 396 If the table argument is None, no translation is applied and 397 the operation simply removes the characters in deletechars. 398 """ 399 return "" 400 401 def upper(self): 402 """ 403 S.upper() -> string 404 405 Return a copy of the string S converted to uppercase. 406 """ 407 return "" 408 409 def zfill(self, width): 410 """方法返回指定长度的字符串,原字符串右对齐,前面填充0。""" 411 """ 412 S.zfill(width) -> string 413 414 Pad a numeric string S with zeros on the left, to fill a field 415 of the specified width. The string S is never truncated. 416 """ 417 return "" 418 419 def _formatter_field_name_split(self, *args, **kwargs): # real signature unknown 420 pass 421 422 def _formatter_parser(self, *args, **kwargs): # real signature unknown 423 pass 424 425 def __add__(self, y): 426 """ x.__add__(y) <==> x+y """ 427 pass 428 429 def __contains__(self, y): 430 """ x.__contains__(y) <==> y in x """ 431 pass 432 433 def __eq__(self, y): 434 """ x.__eq__(y) <==> x==y """ 435 pass 436 437 def __format__(self, format_spec): 438 """ 439 S.__format__(format_spec) -> string 440 441 Return a formatted version of S as described by format_spec. 442 """ 443 return "" 444 445 def __getattribute__(self, name): 446 """ x.__getattribute__('name') <==> x.name """ 447 pass 448 449 def __getitem__(self, y): 450 """ x.__getitem__(y) <==> x[y] """ 451 pass 452 453 def __getnewargs__(self, *args, **kwargs): # real signature unknown 454 pass 455 456 def __getslice__(self, i, j): 457 """ 458 x.__getslice__(i, j) <==> x[i:j] 459 460 Use of negative indices is not supported. 461 """ 462 pass 463 464 def __ge__(self, y): 465 """ x.__ge__(y) <==> x>=y """ 466 pass 467 468 def __gt__(self, y): 469 """ x.__gt__(y) <==> x>y """ 470 pass 471 472 def __hash__(self): 473 """ x.__hash__() <==> hash(x) """ 474 pass 475 476 def __init__(self, string=''): # known special case of str.__init__ 477 """ 478 str(object='') -> string 479 480 Return a nice string representation of the object. 481 If the argument is a string, the return value is the same object. 482 # (copied from class doc) 483 """ 484 pass 485 486 def __len__(self): 487 """ x.__len__() <==> len(x) """ 488 pass 489 490 def __le__(self, y): 491 """ x.__le__(y) <==> x<=y """ 492 pass 493 494 def __lt__(self, y): 495 """ x.__lt__(y) <==> x<y """ 496 pass 497 498 def __mod__(self, y): 499 """ x.__mod__(y) <==> x%y """ 500 pass 501 502 def __mul__(self, n): 503 """ x.__mul__(n) <==> x*n """ 504 pass 505 506 @staticmethod # known case of __new__ 507 def __new__(S, *more): 508 """ T.__new__(S, ...) -> a new object with type S, a subtype of T """ 509 pass 510 511 def __ne__(self, y): 512 """ x.__ne__(y) <==> x!=y """ 513 pass 514 515 def __repr__(self): 516 """ x.__repr__() <==> repr(x) """ 517 pass 518 519 def __rmod__(self, y): 520 """ x.__rmod__(y) <==> y%x """ 521 pass 522 523 def __rmul__(self, n): 524 """ x.__rmul__(n) <==> n*x """ 525 pass 526 527 def __sizeof__(self): 528 """ S.__sizeof__() -> size of S in memory, in bytes """ 529 pass 530 531 def __str__(self): 532 """ x.__str__() <==> str(x) """ 533 pass 534 535 str
3.4 pycharm下整理的字符串
1 t = 'LiuLonghai' 2 v = t.capitalize() 3 print(v) 4 5 # 输出结果:Liulonghai Liulonghai 首字母变成大写,其他地方小写不变,大写的变小写 6 7 t = 'LiuLonghai' 8 v = t.casefold() 9 print(v) 10 11 # 输出结果:liulonghai 把大写字母变成小写,大写的全部变 12 13 t = 'LiuLonghai' 14 v1 = t.center(20,'*') 15 v2 = t.center(20) #以特定的字符在两边进行填充,默认为空格,字符串在中间 16 v3 = t.zfill(20) #只有一个参数,只能用0来填充,其他的字符串不行 17 v4 = t.ljust(20,'#') #以特定的字符在左边进行填充,默认为空格 18 v5 = t.rjust(20,'@') #以特定的字符在右边进行填充,默认为空格 19 print(v1,v2,v3,v4,v5) 20 21 # 输出结果:*****LiuLonghai***** LiuLonghai 0000000000LiuLonghai LiuLonghai########## @@@@@@@@@@LiuLonghai 22 23 t = 'liulonghai' 24 v1 = t.count('l') 25 v2 = t.count('llh') 26 print(v1,v2) 27 28 # 输出结果:2 0 对字符串的子字符串进行计数,若不是子字符串而是不连续的,返回0 29 30 t = 'liulonghai' 31 v1 = t.endswith('i') 32 v2 = t.startswith('l') 33 v3 = t.startswith('n',5,20) 34 print(v1,v2,v3) 35 36 # 输出结果:True True True 判断字符串是否以某个子字符串结尾和开始,若不设置范围,默认全部,范围可以超出字符串的长度 37 38 t = 'liulo\tnghai\t' 39 v = t.expandtabs(20,) 40 print(v) #当遇见制表符时以某个特定的值对字符串进行空格填充,若不设置值,默认为8 41 42 # 输出结果:liulo nghai 43 44 t = 'my name is liulonghai' 45 len_t = len(t) 46 v1 = t.find('haos') 47 v2 = t.rfind('hai') #从右往左进行查找并返回位置 48 v3 = t.index('is') #和find一样,不同在于当没有是程序报错 49 print(v1,v2,len_t) 50 51 # 输出结果:-1 18 21 #找到字符串中子字符串在什么位置并返回是第几个,若无则返回-1,默认从左到右,范围默认全部 52 53 t = 'My name is {},age {}岁' 54 v = t.format('liulonghai','23') 55 print(v) 56 57 # 输出结果:My name is liulonghai,age 23岁 格式化字符串 58 59 t1 = 'lgjislojdsl34jfsdlLL' 60 t2 = 'jfdlgji' 61 t3 = '42739847239二' 62 t4 = '342899427②' 63 v1 = t1.isalpha() #判断字符串是否全是字母 64 v1_1 = t2.isalpha() 65 v2 = t1.isalnum() #判断字符串是否全是字母和数字 66 v2_1 = t3.isalnum() 67 v3 = t1.isnumeric() #判断字符串是否全是数字 68 v3_1 = t3.isnumeric() 69 v4 = t1.isdecimal() #判断字符串是否全是十进制数字,可以判断特殊状态下的数字,入'二' 70 v4_1 = t4.isdecimal() 71 v5 = t4.isdigit() #判断字符串是否全是数字,可以判断中文状态下的数字,入'②' 72 v5_1 = t3.isdigit() 73 print(v1,v1_1,v2,v2_1,v3,v3_1,v4,v4_1,v5,v5_1) 74 75 # 输出结果: False True True True False True False False True False 76 77 t = 'liulo\nnghai' 78 v1 = t.isidentifier() #若字符串是有效的,返回True,否则返回False,如字符串里面有空格,转义字符等 79 v2 = t.isprintable() #若字符串是可显示的,返回True,否则返回False,如字符串里面有空格,转义字符等 80 print(v1,v2) 81 82 # 输出结果:False False 83 84 t = 'Liulong hai' 85 v1 = t.upper() #对字符串进行大写转换 86 v1_1 = t.isupper() #判断字符串是否全是大写 87 v2 = t.lower() #对字符串进行小写转换 88 v2_1 = t.islower() #判断字符串是否全是小写 89 v3 = t.isspace() #断字符串是否全是空格 90 v4 = t.swapcase() #大小写进行相互转换 91 print(v1,v1_1,v2,v2_1,v3,v4) 92 93 # 输出结果:LIULONG HAI False liulong hai False False lIULONG HAI 94 95 t = '你是风儿我是啥!' 96 v1 = ' '.join(t) 97 v2 = ','.join(t) #非常重要,循环遍历字符串,用某个特定的符号(也是字符串)进行分割,有点像split() 98 print(v1) 99 print(v2) 100 101 # 输出结果:你 是 风 儿 我 是 啥 ! 102 # 你,是,风,儿,我,是,啥,! 103 104 t = '你是风儿我是啥!' 105 v1 = t.split('风儿') 106 v2 = t.rsplit('风儿') #以某个子字符串惊醒分割,但不显示子字符串,返回的是另一个列表 107 v3 = t.splitlines(True) #不太懂 108 print(v1) 109 print(v2) 110 print(v3) 111 112 # 输出结果:['你是', '我是啥!'] 113 # ['你是', '我是啥!'] 114 # ['你是风儿我是啥!'] 115 116 t = ' liulonghai ' 117 v1 = t.strip() #去掉前后两边的空白字符 118 v2 = t.rstrip() #去掉右边的空白字符 119 v3 = t.lstrip() #去掉左边的空白字符 120 print(v1) 121 print(v2) 122 print(v3) 123 124 # 输出结果:liulonghai 125 # liulonghai 126 # liulonghai 127 128 t = 'i love python' 129 v1 = t.title() #把字符串转换成标题(每个字符的首字母变成大写) 130 v2 = t.istitle() #判断字符串是否是标题(检查字符串的首字母是否大写,返回bool值) 131 print(v1,v2) 132 133 # 输出结果:I Love Python Fals
4.列表
4.1 列表的创建(用[]中括号括起来的,里面可以是任意字符类型,元素之间以“,”隔开)
1 #遍历列表里面的所有元素 2 li = [1,2,3,'lulonghai','true',[5,6],('a','b'),{'liulonghai':23}] 3 for i in li: 4 print(i)
4.2 列表有以下几个常用功能:
索引
切片
追加
删除
长度
切片
循环
包含
4.3 列表模块下的代码
1 class list(object): 2 """ 3 list() -> new empty list 4 list(iterable) -> new list initialized from iterable's items 5 """ 6 def append(self, p_object): # real signature unknown; restored from __doc__ 7 """ L.append(object) -- append object to end """ 8 pass 9 10 def count(self, value): # real signature unknown; restored from __doc__ 11 """ L.count(value) -> integer -- return number of occurrences of value """ 12 return 0 13 14 def extend(self, iterable): # real signature unknown; restored from __doc__ 15 """ L.extend(iterable) -- extend list by appending elements from the iterable """ 16 pass 17 18 def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ 19 """ 20 L.index(value, [start, [stop]]) -> integer -- return first index of value. 21 Raises ValueError if the value is not present. 22 """ 23 return 0 24 25 def insert(self, index, p_object): # real signature unknown; restored from __doc__ 26 """ L.insert(index, object) -- insert object before index """ 27 pass 28 29 def pop(self, index=None): # real signature unknown; restored from __doc__ 30 """ 31 L.pop([index]) -> item -- remove and return item at index (default last). 32 Raises IndexError if list is empty or index is out of range. 33 """ 34 pass 35 36 def remove(self, value): # real signature unknown; restored from __doc__ 37 """ 38 L.remove(value) -- remove first occurrence of value. 39 Raises ValueError if the value is not present. 40 """ 41 pass 42 43 def reverse(self): # real signature unknown; restored from __doc__ 44 """ L.reverse() -- reverse *IN PLACE* """ 45 pass 46 47 def sort(self, cmp=None, key=None, reverse=False): # real signature unknown; restored from __doc__ 48 """ 49 L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; 50 cmp(x, y) -> -1, 0, 1 51 """ 52 pass 53 54 def __add__(self, y): # real signature unknown; restored from __doc__ 55 """ x.__add__(y) <==> x+y """ 56 pass 57 58 def __contains__(self, y): # real signature unknown; restored from __doc__ 59 """ x.__contains__(y) <==> y in x """ 60 pass 61 62 def __delitem__(self, y): # real signature unknown; restored from __doc__ 63 """ x.__delitem__(y) <==> del x[y] """ 64 pass 65 66 def __delslice__(self, i, j): # real signature unknown; restored from __doc__ 67 """ 68 x.__delslice__(i, j) <==> del x[i:j] 69 70 Use of negative indices is not supported. 71 """ 72 pass 73 74 def __eq__(self, y): # real signature unknown; restored from __doc__ 75 """ x.__eq__(y) <==> x==y """ 76 pass 77 78 def __getattribute__(self, name): # real signature unknown; restored from __doc__ 79 """ x.__getattribute__('name') <==> x.name """ 80 pass 81 82 def __getitem__(self, y): # real signature unknown; restored from __doc__ 83 """ x.__getitem__(y) <==> x[y] """ 84 pass 85 86 def __getslice__(self, i, j): # real signature unknown; restored from __doc__ 87 """ 88 x.__getslice__(i, j) <==> x[i:j] 89 90 Use of negative indices is not supported. 91 """ 92 pass 93 94 def __ge__(self, y): # real signature unknown; restored from __doc__ 95 """ x.__ge__(y) <==> x>=y """ 96 pass 97 98 def __gt__(self, y): # real signature unknown; restored from __doc__ 99 """ x.__gt__(y) <==> x>y """ 100 pass 101 102 def __iadd__(self, y): # real signature unknown; restored from __doc__ 103 """ x.__iadd__(y) <==> x+=y """ 104 pass 105 106 def __imul__(self, y): # real signature unknown; restored from __doc__ 107 """ x.__imul__(y) <==> x*=y """ 108 pass 109 110 def __init__(self, seq=()): # known special case of list.__init__ 111 """ 112 list() -> new empty list 113 list(iterable) -> new list initialized from iterable's items 114 # (copied from class doc) 115 """ 116 pass 117 118 def __iter__(self): # real signature unknown; restored from __doc__ 119 """ x.__iter__() <==> iter(x) """ 120 pass 121 122 def __len__(self): # real signature unknown; restored from __doc__ 123 """ x.__len__() <==> len(x) """ 124 pass 125 126 def __le__(self, y): # real signature unknown; restored from __doc__ 127 """ x.__le__(y) <==> x<=y """ 128 pass 129 130 def __lt__(self, y): # real signature unknown; restored from __doc__ 131 """ x.__lt__(y) <==> x<y """ 132 pass 133 134 def __mul__(self, n): # real signature unknown; restored from __doc__ 135 """ x.__mul__(n) <==> x*n """ 136 pass 137 138 @staticmethod # known case of __new__ 139 def __new__(S, *more): # real signature unknown; restored from __doc__ 140 """ T.__new__(S, ...) -> a new object with type S, a subtype of T """ 141 pass 142 143 def __ne__(self, y): # real signature unknown; restored from __doc__ 144 """ x.__ne__(y) <==> x!=y """ 145 pass 146 147 def __repr__(self): # real signature unknown; restored from __doc__ 148 """ x.__repr__() <==> repr(x) """ 149 pass 150 151 def __reversed__(self): # real signature unknown; restored from __doc__ 152 """ L.__reversed__() -- return a reverse iterator over the list """ 153 pass 154 155 def __rmul__(self, n): # real signature unknown; restored from __doc__ 156 """ x.__rmul__(n) <==> n*x """ 157 pass 158 159 def __setitem__(self, i, y): # real signature unknown; restored from __doc__ 160 """ x.__setitem__(i, y) <==> x[i]=y """ 161 pass 162 163 def __setslice__(self, i, j, y): # real signature unknown; restored from __doc__ 164 """ 165 x.__setslice__(i, j, y) <==> x[i:j]=y 166 167 Use of negative indices is not supported. 168 """ 169 pass 170 171 def __sizeof__(self): # real signature unknown; restored from __doc__ 172 """ L.__sizeof__() -- size of L in memory, in bytes """ 173 pass 174 175 __hash__ = None
5.元组
5.1 元组的创建(用"()"括起来,元素之间以“,”隔开)
1 tup = ('a','b','c',1,2,3)
5.2 元组有以下几个常用功能:
索引
切片
循环
长度
包含
5.3 元组的方法
1 lass tuple(object): 2 """ 3 tuple() -> empty tuple 4 tuple(iterable) -> tuple initialized from iterable's items 5 6 If the argument is a tuple, the return value is the same object. 7 """ 8 def count(self, value): # real signature unknown; restored from __doc__ 9 """ T.count(value) -> integer -- return number of occurrences of value """ 10 return 0 11 12 def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ 13 """ 14 T.index(value, [start, [stop]]) -> integer -- return first index of value. 15 Raises ValueError if the value is not present. 16 """ 17 return 0 18 19 def __add__(self, y): # real signature unknown; restored from __doc__ 20 """ x.__add__(y) <==> x+y """ 21 pass 22 23 def __contains__(self, y): # real signature unknown; restored from __doc__ 24 """ x.__contains__(y) <==> y in x """ 25 pass 26 27 def __eq__(self, y): # real signature unknown; restored from __doc__ 28 """ x.__eq__(y) <==> x==y """ 29 pass 30 31 def __getattribute__(self, name): # real signature unknown; restored from __doc__ 32 """ x.__getattribute__('name') <==> x.name """ 33 pass 34 35 def __getitem__(self, y): # real signature unknown; restored from __doc__ 36 """ x.__getitem__(y) <==> x[y] """ 37 pass 38 39 def __getnewargs__(self, *args, **kwargs): # real signature unknown 40 pass 41 42 def __getslice__(self, i, j): # real signature unknown; restored from __doc__ 43 """ 44 x.__getslice__(i, j) <==> x[i:j] 45 46 Use of negative indices is not supported. 47 """ 48 pass 49 50 def __ge__(self, y): # real signature unknown; restored from __doc__ 51 """ x.__ge__(y) <==> x>=y """ 52 pass 53 54 def __gt__(self, y): # real signature unknown; restored from __doc__ 55 """ x.__gt__(y) <==> x>y """ 56 pass 57 58 def __hash__(self): # real signature unknown; restored from __doc__ 59 """ x.__hash__() <==> hash(x) """ 60 pass 61 62 def __init__(self, seq=()): # known special case of tuple.__init__ 63 """ 64 tuple() -> empty tuple 65 tuple(iterable) -> tuple initialized from iterable's items 66 67 If the argument is a tuple, the return value is the same object. 68 # (copied from class doc) 69 """ 70 pass 71 72 def __iter__(self): # real signature unknown; restored from __doc__ 73 """ x.__iter__() <==> iter(x) """ 74 pass 75 76 def __len__(self): # real signature unknown; restored from __doc__ 77 """ x.__len__() <==> len(x) """ 78 pass 79 80 def __le__(self, y): # real signature unknown; restored from __doc__ 81 """ x.__le__(y) <==> x<=y """ 82 pass 83 84 def __lt__(self, y): # real signature unknown; restored from __doc__ 85 """ x.__lt__(y) <==> x<y """ 86 pass 87 88 def __mul__(self, n): # real signature unknown; restored from __doc__ 89 """ x.__mul__(n) <==> x*n """ 90 pass 91 92 @staticmethod # known case of __new__ 93 def __new__(S, *more): # real signature unknown; restored from __doc__ 94 """ T.__new__(S, ...) -> a new object with type S, a subtype of T """ 95 pass 96 97 def __ne__(self, y): # real signature unknown; restored from __doc__ 98 """ x.__ne__(y) <==> x!=y """ 99 pass 100 101 def __repr__(self): # real signature unknown; restored from __doc__ 102 """ x.__repr__() <==> repr(x) """ 103 pass 104 105 def __rmul__(self, n): # real signature unknown; restored from __doc__ 106 """ x.__rmul__(n) <==> n*x """ 107 pass 108 109 def __sizeof__(self): # real signature unknown; restored from __doc__ 110 """ T.__sizeof__() -- size of T in memory, in bytes """ 111 pass
6.字典
6.1 字典的创建(以键值对的形势存在,用{}括起来,键和值之间用 “:”,键值对之间以“,”隔开)
6.2 字典有以下几个常用功能:
索引
新增
删除
键、值、键值对
循环
长度
6.3 字典的方法
1 class dict(object): 2 """ 3 dict() -> new empty dictionary 4 dict(mapping) -> new dictionary initialized from a mapping object's 5 (key, value) pairs 6 dict(iterable) -> new dictionary initialized as if via: 7 d = {} 8 for k, v in iterable: 9 d[k] = v 10 dict(**kwargs) -> new dictionary initialized with the name=value pairs 11 in the keyword argument list. For example: dict(one=1, two=2) 12 """ 13 14 def clear(self): # real signature unknown; restored from __doc__ 15 """ 清除内容 """ 16 """ D.clear() -> None. Remove all items from D. """ 17 pass 18 19 def copy(self): # real signature unknown; restored from __doc__ 20 """ 浅拷贝 """ 21 """ D.copy() -> a shallow copy of D """ 22 pass 23 24 @staticmethod # known case 25 def fromkeys(S, v=None): # real signature unknown; restored from __doc__ 26 """ 27 dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v. 28 v defaults to None. 29 """ 30 pass 31 32 def get(self, k, d=None): # real signature unknown; restored from __doc__ 33 """ 根据key获取值,d是默认值 """ 34 """ D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. """ 35 pass 36 37 def has_key(self, k): # real signature unknown; restored from __doc__ 38 """ 是否有key """ 39 """ D.has_key(k) -> True if D has a key k, else False """ 40 return False 41 42 def items(self): # real signature unknown; restored from __doc__ 43 """ 所有项的列表形式 """ 44 """ D.items() -> list of D's (key, value) pairs, as 2-tuples """ 45 return [] 46 47 def iteritems(self): # real signature unknown; restored from __doc__ 48 """ 项可迭代 """ 49 """ D.iteritems() -> an iterator over the (key, value) items of D """ 50 pass 51 52 def iterkeys(self): # real signature unknown; restored from __doc__ 53 """ key可迭代 """ 54 """ D.iterkeys() -> an iterator over the keys of D """ 55 pass 56 57 def itervalues(self): # real signature unknown; restored from __doc__ 58 """ value可迭代 """ 59 """ D.itervalues() -> an iterator over the values of D """ 60 pass 61 62 def keys(self): # real signature unknown; restored from __doc__ 63 """ 所有的key列表 """ 64 """ D.keys() -> list of D's keys """ 65 return [] 66 67 def pop(self, k, d=None): # real signature unknown; restored from __doc__ 68 """ 获取并在字典中移除 """ 69 """ 70 D.pop(k[,d]) -> v, remove specified key and return the corresponding value. 71 If key is not found, d is returned if given, otherwise KeyError is raised 72 """ 73 pass 74 75 def popitem(self): # real signature unknown; restored from __doc__ 76 """ 获取并在字典中移除 """ 77 """ 78 D.popitem() -> (k, v), remove and return some (key, value) pair as a 79 2-tuple; but raise KeyError if D is empty. 80 """ 81 pass 82 83 def setdefault(self, k, d=None): # real signature unknown; restored from __doc__ 84 """ 如果key不存在,则创建,如果存在,则返回已存在的值且不修改 """ 85 """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """ 86 pass 87 88 def update(self, E=None, **F): # known special case of dict.update 89 """ 更新 90 {'name':'alex', 'age': 18000} 91 [('name','sbsbsb'),] 92 """ 93 """ 94 D.update([E, ]**F) -> None. Update D from dict/iterable E and F. 95 If E present and has a .keys() method, does: for k in E: D[k] = E[k] 96 If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v 97 In either case, this is followed by: for k in F: D[k] = F[k] 98 """ 99 pass 100 101 def values(self): # real signature unknown; restored from __doc__ 102 """ 所有的值 """ 103 """ D.values() -> list of D's values """ 104 return [] 105 106 def viewitems(self): # real signature unknown; restored from __doc__ 107 """ 所有项,只是将内容保存至view对象中 """ 108 """ D.viewitems() -> a set-like object providing a view on D's items """ 109 pass 110 111 def viewkeys(self): # real signature unknown; restored from __doc__ 112 """ D.viewkeys() -> a set-like object providing a view on D's keys """ 113 pass 114 115 def viewvalues(self): # real signature unknown; restored from __doc__ 116 """ D.viewvalues() -> an object providing a view on D's values """ 117 pass 118 119 def __cmp__(self, y): # real signature unknown; restored from __doc__ 120 """ x.__cmp__(y) <==> cmp(x,y) """ 121 pass 122 123 def __contains__(self, k): # real signature unknown; restored from __doc__ 124 """ D.__contains__(k) -> True if D has a key k, else False """ 125 return False 126 127 def __delitem__(self, y): # real signature unknown; restored from __doc__ 128 """ x.__delitem__(y) <==> del x[y] """ 129 pass 130 131 def __eq__(self, y): # real signature unknown; restored from __doc__ 132 """ x.__eq__(y) <==> x==y """ 133 pass 134 135 def __getattribute__(self, name): # real signature unknown; restored from __doc__ 136 """ x.__getattribute__('name') <==> x.name """ 137 pass 138 139 def __getitem__(self, y): # real signature unknown; restored from __doc__ 140 """ x.__getitem__(y) <==> x[y] """ 141 pass 142 143 def __ge__(self, y): # real signature unknown; restored from __doc__ 144 """ x.__ge__(y) <==> x>=y """ 145 pass 146 147 def __gt__(self, y): # real signature unknown; restored from __doc__ 148 """ x.__gt__(y) <==> x>y """ 149 pass 150 151 def __init__(self, seq=None, **kwargs): # known special case of dict.__init__ 152 """ 153 dict() -> new empty dictionary 154 dict(mapping) -> new dictionary initialized from a mapping object's 155 (key, value) pairs 156 dict(iterable) -> new dictionary initialized as if via: 157 d = {} 158 for k, v in iterable: 159 d[k] = v 160 dict(**kwargs) -> new dictionary initialized with the name=value pairs 161 in the keyword argument list. For example: dict(one=1, two=2) 162 # (copied from class doc) 163 """ 164 pass 165 166 def __iter__(self): # real signature unknown; restored from __doc__ 167 """ x.__iter__() <==> iter(x) """ 168 pass 169 170 def __len__(self): # real signature unknown; restored from __doc__ 171 """ x.__len__() <==> len(x) """ 172 pass 173 174 def __le__(self, y): # real signature unknown; restored from __doc__ 175 """ x.__le__(y) <==> x<=y """ 176 pass 177 178 def __lt__(self, y): # real signature unknown; restored from __doc__ 179 """ x.__lt__(y) <==> x<y """ 180 pass 181 182 @staticmethod # known case of __new__ 183 def __new__(S, *more): # real signature unknown; restored from __doc__ 184 """ T.__new__(S, ...) -> a new object with type S, a subtype of T """ 185 pass 186 187 def __ne__(self, y): # real signature unknown; restored from __doc__ 188 """ x.__ne__(y) <==> x!=y """ 189 pass 190 191 def __repr__(self): # real signature unknown; restored from __doc__ 192 """ x.__repr__() <==> repr(x) """ 193 pass 194 195 def __setitem__(self, i, y): # real signature unknown; restored from __doc__ 196 """ x.__setitem__(i, y) <==> x[i]=y """ 197 pass 198 199 def __sizeof__(self): # real signature unknown; restored from __doc__ 200 """ D.__sizeof__() -> size of D in memory, in bytes """ 201 pass 202 203 __hash__ = None
7.集合
7.1 集合的创建(以{}括起来,元素之间以“,”隔开)
1 class set(object): 2 """ 3 set() -> new empty set object 4 set(iterable) -> new set object 5 6 Build an unordered collection of unique elements. 7 """ 8 def add(self, *args, **kwargs): # real signature unknown 9 """ 10 Add an element to a set. 11 12 This has no effect if the element is already present. 13 """ 14 pass 15 16 def clear(self, *args, **kwargs): # real signature unknown 17 """ Remove all elements from this set. """ 18 pass 19 20 def copy(self, *args, **kwargs): # real signature unknown 21 """ Return a shallow copy of a set. """ 22 pass 23 24 def difference(self, *args, **kwargs): # real signature unknown 25 """ 26 Return the difference of two or more sets as a new set. 27 28 (i.e. all elements that are in this set but not the others.) 29 """ 30 pass 31 32 def difference_update(self, *args, **kwargs): # real signature unknown 33 """ Remove all elements of another set from this set. """ 34 pass 35 36 def discard(self, *args, **kwargs): # real signature unknown 37 """ 38 Remove an element from a set if it is a member. 39 40 If the element is not a member, do nothing. 41 """ 42 pass 43 44 def intersection(self, *args, **kwargs): # real signature unknown 45 """ 46 Return the intersection of two sets as a new set. 47 48 (i.e. all elements that are in both sets.) 49 """ 50 pass 51 52 def intersection_update(self, *args, **kwargs): # real signature unknown 53 """ Update a set with the intersection of itself and another. """ 54 pass 55 56 def isdisjoint(self, *args, **kwargs): # real signature unknown 57 """ Return True if two sets have a null intersection. """ 58 pass 59 60 def issubset(self, *args, **kwargs): # real signature unknown 61 """ Report whether another set contains this set. """ 62 pass 63 64 def issuperset(self, *args, **kwargs): # real signature unknown 65 """ Report whether this set contains another set. """ 66 pass 67 68 def pop(self, *args, **kwargs): # real signature unknown 69 """ 70 Remove and return an arbitrary set element. 71 Raises KeyError if the set is empty. 72 """ 73 pass 74 75 def remove(self, *args, **kwargs): # real signature unknown 76 """ 77 Remove an element from a set; it must be a member. 78 79 If the element is not a member, raise a KeyError. 80 """ 81 pass 82 83 def symmetric_difference(self, *args, **kwargs): # real signature unknown 84 """ 85 Return the symmetric difference of two sets as a new set. 86 87 (i.e. all elements that are in exactly one of the sets.) 88 """ 89 pass 90 91 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown 92 """ Update a set with the symmetric difference of itself and another. """ 93 pass 94 95 def union(self, *args, **kwargs): # real signature unknown 96 """ 97 Return the union of sets as a new set. 98 99 (i.e. all elements that are in either set.) 100 """ 101 pass 102 103 def update(self, *args, **kwargs): # real signature unknown 104 """ Update a set with the union of itself and others. """ 105 pass
三、基本数据类型的相关作业
1、以后更新