A function with one parameter can be called without argument if a default value is defned for the function's parameter
时间: 2024-01-01 20:04:40 浏览: 90
Yes, that is correct. In Python, you can define a default value for a function parameter. If a default value is defined for a parameter, the function can be called without passing an argument for that parameter. If an argument is not provided, the default value is used instead.
Here is an example:
```python
def greet(name="World"):
print("Hello, " + name + "!")
# Call the function with an argument
greet("Alice") # Output: Hello, Alice!
# Call the function without an argument
greet() # Output: Hello, World!
```
In the example above, the `greet()` function has a parameter called `name` with a default value of `"World"`. When we call the function with the argument `"Alice"`, it prints `"Hello, Alice!"`. When we call the function without an argument, it uses the default value of `"World"` and prints `"Hello, World!"`.
阅读全文