Last answered:

14 Sept 2023

Posted on:

14 Sept 2023

0

Structure your code with indentation

Hey if we defining a function then why we wrote five instead function and why we are giving 1,2,3... Numbers when argumenting

1 answers ( 0 marked as helpful)
Instructor
Posted on:

14 Sept 2023

3

Hi Ambuj!

Thanks for reaching out!

In the function definition, the function five is defined to take a parameter x.
Inside the function, regardless of the passed argument, x is immediately assigned a value of 5.
The function then returns this value.

When you call the function using five(3), the argument 3 is passed to the function. However, the function doesn't use this value because x is immediately overwritten with the value 5.
Thus, the function will always return 5, irrespective of the argument provided.


In the provided example, we do this to demonstrate the difference between parameters and arguments in Python functions. By using different values, we can clearly illustrate how Python functions prioritize those, and in doing so, we get a clearer understanding of how parameters and arguments work in Python.


 

Hope this helps.

Best,

Ivan

Submit an answer