+ 1

What is function argument

Explain it simply with a an example

22nd Jan 2018, 2:47 PM
Nathan Croft
3 Réponses
+ 4
Example (Python 3.6): # Declaring function with two parameters def sum(a, b): # Parameters are a, b print(a + b) # Now we call function sum with two arguments sum(5, 10) # Arguments are 5, 10 # Note that we need to pass the same amount of arguments as the amount of the parameters. # Wrong calls of our sum function: sum() # No arguments sum(5) # One argument sum(5, 10, 15) # Three arguments
22nd Jan 2018, 3:09 PM
Boris Batinkov
Boris Batinkov - avatar
+ 6
When you call print(“hi”), it knows what to print because you gave it the argument, “hi”. It works the same way with functions you define. Inside the function, those arguments act as new variables that get deleted when the function ends. At the beginning, they are given the values of the arguments passed to the function. After that, you can use them just like variables inside the function.
22nd Jan 2018, 2:52 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
The variables that are used in the FUNCTION are commonly called Parameters... And the variables/values that are passed to the function is called Arguments.... eg.: def fnsub(a,b): return a-b #function call print(fnsub(10,5)) where the variables a and b are used with in the function...as Parameters. and the values 10 and 5 are passed to the function...as Arguments...
4th Feb 2018, 11:56 AM
Shivadharshini Nagaraju
Shivadharshini Nagaraju - avatar