python内置函数源代码_4.内置函数源码总结

1 def abs(*args, **kwargs): #real signature unknown

2 """Return the absolute value of the argument."""

3 pass

4 #abs(*args, **kwargs)#返回参数的绝对值,可接收任何数据类型

5 #?绝对值如何接收数值意外的类型得到什么样的结果。(报错,应该是不可接收)

6

7 def all(*args, **kwargs): #real signature unknown

8 """

9 Return True if bool(x) is True for all values x in the iterable.10

11 If the iterable is empty, return True.12 """

13 pass

14

15

16 def any(*args, **kwargs): #real signature unknown

17 """

18 Return True if bool(x) is True for any x in the iterable.19

20 If the iterable is empty, return False.21 """

22 pass

23

24

25 def ascii(*args, **kwargs): #real signature unknown

26 """

27 Return an ASCII-only representation of an object.28

29 As repr(), return a string containing a printable representation of an30 object, but escape the non-ASCII characters in the string returned by31 repr() using \\x, \\u or \\U escapes. This generates a string similar32 to that returned by repr() in Python 2.33 """

34 pass

35

36

37 def bin(*args, **kwargs): #real signature unknown; NOTE: unreliably restored from __doc__

38 """

39 Return the binary representation of an integer.40

41 >>> bin(2796202)42 '0b1010101010101010101010'43 """

44 pass

45

46

47 def callable(i_e_, some_kind_of_function): #real signature unknown; restored from __doc__

48 """

49 Return whether the object is callable (i.e., some kind of function).50

51 Note that classes are callable, as are instances of classes with a52 __call__() method.53 """

54 pass

55

56

57 def chr(*args, **kwargs): #real signature unknown

58 """Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."""

59 pass

60

61

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

63 """

64 Compile source into a code object that can be executed by exec() or eval().65

66 The source code may represent a Python module, statement or expression.67 The filename will be used for run-time error messages.68 The mode must be 'exec' to compile a module, 'single' to compile a69 single (interactive) statement, or 'eval' to compile an expression.70 The flags argument, if present, controls which future statements influence71 the compilation of the code.72 The dont_inherit argument, if true, stops the compilation inheriting73 the effects of any future statements in effect in the code calling74 compile; if absent or false these statements do influence the compilation,75 in addition to any features explicitly specified.76 """

77 pass

78

79

80 def copyright(*args, **kwargs): #real signature unknown

81 """

82 interactive prompt objects for printing the license text, a list of83 contributors and the copyright notice.84 """

85 pass

86

87

88 def credits(*args, **kwargs): #real signature unknown

89 """

90 interactive prompt objects for printing the license text, a list of91 contributors and the copyright notice.92 """

93 pass

94

95

96 def delattr(x, y): #real signature unknown; restored from __doc__

97 """

98 Deletes the named attribute from the given object.99

100 delattr(x, 'y') is equivalent to ``del x.y''101 """

102 pass

103

104

105 def dir(p_object=None): #real signature unknown; restored from __doc__

106 """

107 dir([object]) -> list of strings108

109 If called without an argument, return the names in the current scope.110 Else, return an alphabetized list of names comprising (some of) the attributes111 of the given object, and of attributes reachable from it.112 If the object supplies a method named __dir__, it will be used; otherwise113 the default dir() logic is used and returns:114 for a module object: the module's attributes.115 for a class object: its attributes, and recursively the attributes116 of its bases.117 for any other object: its attributes, its class's attributes, and118 recursively the attributes of its class's base classes.119 """

120 return[]121

122

123 def divmod(x, y): #known case of builtins.divmod

124 """Return the tuple (x//y, x%y). Invariant: div*y + mod == x."""

125 return(0, 0)126

127

128 def eval(*args, **kwargs): #real signature unknown

129 """

130 Evaluate the given source in the context of globals and locals.131

132 The source may be a string representing a Python expression133 or a code object as returned by compile().134 The globals must be a dictionary and locals can be any mapping,135 defaulting to the current globals and locals.136 If only globals is given, locals defaults to it.137 """

138 pass

139

140

141 def exec(*args, **kwargs): #real signature unknown

142 """

143 Execute the given source in the context of globals and locals.144

145 The source may be a string representing one or more Python statements146 or a code object as returned by compile().147 The globals must be a dictionary and locals can be any mapping,148 defaulting to the current globals and locals.149 If only globals is given, locals defaults to it.150 """

151 pass

152

153

154 def exit(*args, **kwargs): #real signature unknown

155 pass

156

157

158 def format(*args, **kwargs): #real signature unknown

159 """

160 Return value.__format__(format_spec)161

162 format_spec defaults to the empty string163 """

164 pass

165

166

167 def getattr(object, name, default=None): #known special case of getattr

168 """

169 getattr(object, name[, default]) -> value170

171 Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.172 When a default argument is given, it is returned when the attribute doesn't173 exist; without it, an exception is raised in that case.174 """

175 pass

176

177

178 def globals(*args, **kwargs): #real signature unknown

179 """

180 Return the dictionary containing the current scope's global variables.181

182 NOTE: Updates to this dictionary *will* affect name lookups in the current183 global scope and vice-versa.184 """

185 pass

186

187

188 def hasattr(*args, **kwargs): #real signature unknown

189 """

190 Return whether the object has an attribute with the given name.191

192 This is done by calling getattr(obj, name) and catching AttributeError.193 """

194 pass

195

196

197 def hash(*args, **kwargs): #real signature unknown

198 """

199 Return the hash value for the given object.200

201 Two objects that compare equal must also have the same hash value, but the202 reverse is not necessarily true.203 """

204 pass

205

206

207 def help(): #real signature unknown; restored from __doc__

208 """

209 Define the builtin 'help'.210

211 This is a wrapper around pydoc.help that provides a helpful message212 when 'help' is typed at the Python interactive prompt.213

214 Calling help() at the Python prompt starts an interactive help session.215 Calling help(thing) prints help for the python object 'thing'.216 """

217 pass

218

219

220 def hex(*args, **kwargs): #real signature unknown; NOTE: unreliably restored from __doc__

221 """

222 Return the hexadecimal representation of an integer.223

224 >>> hex(12648430)225 '0xc0ffee'226 """

227 pass

228

229

230 def id(*args, **kwargs): #real signature unknown

231 """

232 Return the identity of an object.233

234 This is guaranteed to be unique among simultaneously existing objects.235 (CPython uses the object's memory address.)236 """

237 pass

238

239

240 def input(*args, **kwargs): #real signature unknown

241 """

242 Read a string from standard input. The trailing newline is stripped.243

244 The prompt string, if given, is printed to standard output without a245 trailing newline before reading input.246

247 If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.248 On *nix systems, readline is used if available.249 """

250 pass

251

252

253 def isinstance(x, A_tuple): #real signature unknown; restored from __doc__

254 """

255 Return whether an object is an instance of a class or of a subclass thereof.256

257 A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to258 check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)259 or ...`` etc.260 """

261 pass

262

263

264 def issubclass(x, A_tuple): #real signature unknown; restored from __doc__

265 """

266 Return whether 'cls' is a derived from another class or is the same class.267

268 A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to269 check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)270 or ...`` etc.271 """

272 pass

273

274

275 def iter(source, sentinel=None): #known special case of iter

276 """

277 iter(iterable) -> iterator278 iter(callable, sentinel) -> iterator279

280 Get an iterator from an object. In the first form, the argument must281 supply its own iterator, or be a sequence.282 In the second form, the callable is called until it returns the sentinel.283 """

284 pass

285

286

287 def len(*args, **kwargs): #real signature unknown

288 """Return the number of items in a container."""

289 pass

290

291

292 def license(*args, **kwargs): #real signature unknown

293 """

294 interactive prompt objects for printing the license text, a list of295 contributors and the copyright notice.296 """

297 pass

298

299

300 def locals(*args, **kwargs): #real signature unknown

301 """

302 Return a dictionary containing the current scope's local variables.303

304 NOTE: Whether or not updates to this dictionary will affect name lookups in305 the local scope and vice-versa is *implementation dependent* and not306 covered by any backwards compatibility guarantees.307 """

308 pass

309

310

311 def max(*args, key=None): #known special case of max

312 """

313 max(iterable, *[, default=obj, key=func]) -> value314 max(arg1, arg2, *args, *[, key=func]) -> value315

316 With a single iterable argument, return its biggest item. The317 default keyword-only argument specifies an object to return if318 the provided iterable is empty.319 With two or more arguments, return the largest argument.320 """

321 pass

322

323

324 def min(*args, key=None): #known special case of min

325 """

326 min(iterable, *[, default=obj, key=func]) -> value327 min(arg1, arg2, *args, *[, key=func]) -> value328

329 With a single iterable argument, return its smallest item. The330 default keyword-only argument specifies an object to return if331 the provided iterable is empty.332 With two or more arguments, return the smallest argument.333 """

334 pass

335

336

337 def next(iterator, default=None): #real signature unknown; restored from __doc__

338 """

339 next(iterator[, default])340

341 Return the next item from the iterator. If default is given and the iterator342 is exhausted, it is returned instead of raising StopIteration.343 """

344 pass

345

346

347 def oct(*args, **kwargs): #real signature unknown; NOTE: unreliably restored from __doc__

348 """

349 Return the octal representation of an integer.350

351 >>> oct(342391)352 '0o1234567'353 """

354 pass

355

356

357 def open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None,358 closefd=True): #known special case of open

359 """

360 Open file and return a stream. Raise IOError upon failure.361

362 file is either a text or byte string giving the name (and the path363 if the file isn't in the current working directory) of the file to364 be opened or an integer file descriptor of the file to be365 wrapped. (If a file descriptor is given, it is closed when the366 returned I/O object is closed, unless closefd is set to False.)367

368 mode is an optional string that specifies the mode in which the file369 is opened. It defaults to 'r' which means open for reading in text370 mode. Other common values are 'w' for writing (truncating the file if371 it already exists), 'x' for creating and writing to a new file, and372 'a' for appending (which on some Unix systems, means that all writes373 append to the end of the file regardless of the current seek position).374 In text mode, if encoding is not specified the encoding used is platform375 dependent: locale.getpreferredencoding(False) is called to get the376 current locale encoding. (For reading and writing raw bytes use binary377 mode and leave encoding unspecified.) The available modes are:378

379 ========= ===============================================================380 Character Meaning381 --------- ---------------------------------------------------------------382 'r' open for reading (default)383 'w' open for writing, truncating the file first384 'x' create a new file and open it for writing385 'a' open for writing, appending to the end of the file if it exists386 'b' binary mode387 't' text mode (default)388 '+' open a disk file for updating (reading and writing)389 'U' universal newline mode (deprecated)390 ========= ===============================================================391

392 The default mode is 'rt' (open for reading text). For binary random393 access, the mode 'w+b' opens and truncates the file to 0 bytes, while394 'r+b' opens the file without truncation. The 'x' mode implies 'w' and395 raises an `FileExistsError` if the file already exists.396

397 Python distinguishes between files opened in binary and text modes,398 even when the underlying operating system doesn't. Files opened in399 binary mode (appending 'b' to the mode argument) return contents as400 bytes objects without any decoding. In text mode (the default, or when401 't' is appended to the mode argument), the contents of the file are402 returned as strings, the bytes having been first decoded using a403 platform-dependent encoding or using the specified encoding if given.404

405 'U' mode is deprecated and will raise an exception in future versions406 of Python. It has no effect in Python 3. Use newline to control407 universal newlines mode.408

409 buffering is an optional integer used to set the buffering policy.410 Pass 0 to switch buffering off (only allowed in binary mode), 1 to select411 line buffering (only usable in text mode), and an integer > 1 to indicate412 the size of a fixed-size chunk buffer. When no buffering argument is413 given, the default buffering policy works as follows:414

415 * Binary files are buffered in fixed-size chunks; the size of the buffer416 is chosen using a heuristic trying to determine the underlying device's417 "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.418 On many systems, the buffer will typically be 4096 or 8192 bytes long.419

420 * "Interactive" text files (files for which isatty() returns True)421 use line buffering. Other text files use the policy described above422 for binary files.423

424 encoding is the name of the encoding used to decode or encode the425 file. This should only be used in text mode. The default encoding is426 platform dependent, but any encoding supported by Python can be427 passed. See the codecs module for the list of supported encodings.428

429 errors is an optional string that specifies how encoding errors are to430 be handled---this argument should not be used in binary mode. Pass431 'strict' to raise a ValueError exception if there is an encoding error432 (the default of None has the same effect), or pass 'ignore' to ignore433 errors. (Note that ignoring encoding errors can lead to data loss.)434 See the documentation for codecs.register or run 'help(codecs.Codec)'435 for a list of the permitted encoding error strings.436

437 newline controls how universal newlines works (it only applies to text438 mode). It can be None, '', '\n', '\r', and '\r\n'. It works as439 follows:440

441 * On input, if newline is None, universal newlines mode is442 enabled. Lines in the input can end in '\n', '\r', or '\r\n', and443 these are translated into '\n' before being returned to the444 caller. If it is '', universal newline mode is enabled, but line445 endings are returned to the caller untranslated. If it has any of446 the other legal values, input lines are only terminated by the given447 string, and the line ending is returned to the caller untranslated.448

449 * On output, if newline is None, any '\n' characters written are450 translated to the system default line separator, os.linesep. If451 newline is '' or '\n', no translation takes place. If newline is any452 of the other legal values, any '\n' characters written are translated453 to the given string.454

455 If closefd is False, the underlying file descriptor will be kept open456 when the file is closed. This does not work when a file name is given457 and must be True in that case.458

459 A custom opener can be used by passing a callable as *opener*. The460 underlying file descriptor for the file object is then obtained by461 calling *opener* with (*file*, *flags*). *opener* must return an open462 file descriptor (passing os.open as *opener* results in functionality463 similar to passing None).464

465 open() returns a file object whose type depends on the mode, and466 through which the standard file operations such as reading and writing467 are performed. When open() is used to open a file in a text mode ('w',468 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open469 a file in a binary mode, the returned class varies: in read binary470 mode, it returns a BufferedReader; in write binary and append binary471 modes, it returns a BufferedWriter, and in read/write mode, it returns472 a BufferedRandom.473

474 It is also possible to use a string or bytearray as a file for both475 reading and writing. For strings StringIO can be used like a file476 opened in a text mode, and for bytes a BytesIO can be used like a file477 opened in a binary mode.478 """

479 pass

480

481

482 def ord(*args, **kwargs): #real signature unknown

483 """Return the Unicode code point for a one-character string."""

484 pass

485

486

487 def pow(*args, **kwargs): #real signature unknown

488 """

489 Equivalent to x**y (with two arguments) or x**y % z (with three arguments)490

491 Some types, such as ints, are able to use a more efficient algorithm when492 invoked using the three argument form.493 """

494 pass

495

496

497 def print(self, *args, sep=' ', end='\n', file=None): #known special case of print

498 """

499 print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)500

501 Prints the values to a stream, or to sys.stdout by default.502 Optional keyword arguments:503 file: a file-like object (stream); defaults to the current sys.stdout.504 sep: string inserted between values, default a space.505 end: string appended after the last value, default a newline.506 flush: whether to forcibly flush the stream.507 """

508 pass

509

510

511 def quit(*args, **kwargs): #real signature unknown

512 pass

513

514

515 def repr(obj): #real signature unknown; restored from __doc__

516 """

517 Return the canonical string representation of the object.518

519 For many object types, including most builtins, eval(repr(obj)) == obj.520 """

521 pass

522

523

524 def round(number, ndigits=None): #real signature unknown; restored from __doc__

525 """

526 round(number[, ndigits]) -> number527

528 Round a number to a given precision in decimal digits (default 0 digits).529 This returns an int when called with one argument, otherwise the530 same type as the number. ndigits may be negative.531 """

532 return0533

534

535 def setattr(x, y, v): #real signature unknown; restored from __doc__

536 """

537 Sets the named attribute on the given object to the specified value.538

539 setattr(x, 'y', v) is equivalent to ``x.y = v''540 """

541 pass

542

543

544 def sorted(*args, **kwargs): #real signature unknown

545 """

546 Return a new list containing all items from the iterable in ascending order.547

548 A custom key function can be supplied to customise the sort order, and the549 reverse flag can be set to request the result in descending order.550 """

551 pass

552

553

554 def sum(*args, **kwargs): #real signature unknown

555 """

556 Return the sum of a 'start' value (default: 0) plus an iterable of numbers557

558 When the iterable is empty, return the start value.559 This function is intended specifically for use with numeric values and may560 reject non-numeric types.561 """

562 pass

563

564

565 def vars(p_object=None): #real signature unknown; restored from __doc__

566 """

567 vars([object]) -> dictionary568

569 Without arguments, equivalent to locals().570 With an argument, equivalent to object.__dict__.571 """

572 return{}573

574

575 def __build_class__(func, name, *bases, metaclass=None, **kwds): #real signature unknown; restored from __doc__

576 """

577 __build_class__(func, name, *bases, metaclass=None, **kwds) -> class578

579 Internal helper function used by the class statement.580 """

581 pass

582

583

584 def __import__(name, globals=None, locals=None, fromlist=(), level=0): #real signature unknown; restored from __doc__

585 """

586 __import__(name, globals=None, locals=None, fromlist=(), level=0) -> module587

588 Import a module. Because this function is meant for use by the Python589 interpreter and not for general use it is better to use590 importlib.import_module() to programmatically import a module.591

592 The globals argument is only used to determine the context;593 they are not modified. The locals argument is unused. The fromlist594 should be a list of names to emulate ``from name import ...'', or an595 empty list to emulate ``import name''.596 When importing a module from a package, note that __import__('A.B', ...)597 returns package A when fromlist is empty, but its submodule B when598 fromlist is not empty. Level is used to determine whether to perform599 absolute or relative imports. 0 is absolute while a positive number600 is the number of parent directories to search relative to the current module.601 """

602 pass

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值