Explanation:
1. Function Definition
def fun(*args):
def is used to define a function.
fun is the function name.
*args means the function can accept any number of arguments.
All arguments passed to the function are stored in a tuple called args.
2. Return Statement
return args[0] + args[-1]
args[0] refers to the first element of the tuple.
args[-1] refers to the last element of the tuple.
The function adds the first and last values.
return sends this result back to where the function was called.
3. Function Call
print(fun(1, 2, 3, 4))
The function fun is called with arguments 1, 2, 3, 4.
These values are stored as:
args = (1, 2, 3, 4)
First value → 1
Last value → 4
Sum → 1 + 4 = 5
4. Output
5
The print function displays the returned result.
Final output is 5 ✅

0 Comments:
Post a Comment