很多Python函數或者類的方法中,幫助文檔都顯示最後有一個斜線,但是自己定義函數時卻不允許這樣用,請問這個斜線的作用是什麼呢?
help(sum)
Help on built-in function sum in module builtins:
sum(iterable, start=0, /)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
>>> help(id)
Help on built-in function id in module builtins:
id(obj, /)
Return the identity of an object.
This is guaranteed to be unique among simultaneously existing objects.
(CPython uses the object's memory address.)
help(input)
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
>>> help(filter)
Help on class filter in module builtins:
class filter(object)
| filter(function or None, iterable) --> filter object
|
| Return an iterator yielding those items of iterable for which function(item)
| is true. If function is None, return the items that are true.
|
| Methods defined here:
|
| getattribute(self, name, /)
| Return getattr(self, name).
|
| iter(self, /)
| Implement iter(self).
|
| new(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| next(self, /)
| Implement next(self).
|
| reduce(...)
| Return state information for pickling.
可變參數個數,後面可以跟任意個數的數字