python __defaults__
时间: 2023-10-16 07:13:03 浏览: 29
The `__defaults__` attribute is a built-in attribute in Python that is used to access the default values of the arguments of a function. This attribute is a tuple that contains the default values of the function's arguments in the order in which they were defined.
For example, consider the following function:
```python
def greet(name, greeting='Hello'):
print(greeting, name)
```
In this function, `name` is a required argument, while `greeting` has a default value of `'Hello'`. We can access the default values of the arguments using the `__defaults__` attribute:
```python
>>> greet.__defaults__
('Hello',)
```
This returns a tuple containing the default value of the `greeting` argument, which is `'Hello'`. If there were multiple arguments with default values, they would appear in the tuple in the order in which they were defined. If there are no default values, `__defaults__` returns `None`.