Hello all. I have 3 questions concerning something in python and I wanted to make sure I was correct seeing as to how this is my first python class.
Consider the following code here:
def make_plot(data, x_values, y_values, save_file=True):
We just have to be able to point out the arguments, optional arguments, and required arguments.
I think the arguments are : data, x_values, y_values, save_file = True
I think the optional argument is: save_file = True
Am I correct so far about the arguments and optional arguments? I'm not sure what the required arguments are. Any help identifying the arguments, optional arguments, and required arguments would be greatly appreciated.
Functions can have required and optional arguments.
def make_plot(data, x_values, y_values, save_file=True):
In the above function declaration the arguments are 'data, x_values, y_values, save_file=True'
The required arguments are 'data, x_values, y_values' .
The optinal arguments are 'save_file=True'
For optional arguments the default value is assigned by using assignment(=) operator of the form keywordname=value.For required arguments we don't need any default value to be assigned.
For your clarification i have provided one example below:
def f(required_arg, optional_arg1 = "1"):
#Create function with optional argument
`optional_arg1`
print(required_arg, optional_arg1)
f("a")
#Call `f` using default value for
`optional_arg1`
f("a", "b")
#Call `f` using `"b"` for `optional_arg1`
OUTPUT:
a 1
a b
Get Answers For Free
Most questions answered within 1 hours.