I am learning python 3 and programming in general for the first time, but I can’t seem to distinguish a parameter and a variable?
Advertisement
Answer
A variable is just something that refers/points to some data you have.
JavaScript
x
2
1
x = 5
2
Here x is a variable. Variables can point to more kinds of data than just numbers, though. They can point to strings, functions, etc.
A parameter is something that is passed into a function
JavaScript
1
3
1
def my_function(y):
2
print(y)
3
Here y is a parameter. It doesn’t contain a value yet. But if I want to call the function, I need to provide an argument to the function.
An argument is the actual value you provide to the function that replaces the parameter.
JavaScript
1
2
1
my_function(5)
2
Here, 5 is the argument. Of course, since x points to the value “5”, I can do this too:
JavaScript
1
2
1
my_function(x)
2
which also prints 5