+ 5
what is the difference between attribute, argument and parameter exactly?
7 ответов
+ 5
A parameter is a temporary variable that a function uses to receive a value in order to run the code.
def Car (make, model): #make and #model are the parameters.
if make == "Nissan":
print ("Who drives a nissan? Lol.")
if model == "Self Driving Car":
print ("Self Driving? I bet it was programmed in anything but python...")
An argument is the value passed to the function. It supplies the value to the parameter of the function.
Car ("Nissan", "Self Driving Car")
An attribute is a variable or method of a class. Instances of a class can access those attributes.
class Colour:
description = "This is a colour"
def __init__(self, colour):
self.colour = colour
def doSomething (self):
print ("I am", self.colour)
colour1 = Colour ("blue")
colour1.description //description is the attribute
colour1.doSomething ()
0
thank you, much more clear!!! so as you sad, an argument can be a method also. In your example doSomething is an attribute too?
0
Yes, you can supply a method as an argument if that method returns a value.
And yes the method doSomething is an attribute of the class.
0
ooookeee. you helped me a lot!
0
Your welcome
0
parameters are passed to function when declaring them
a function lile this (python syntax)
def func(a,b,c):
#code block
the a,b,c enclosed in the parnthesis are the parameters of that function
they can be also called local variables to that function in such that they hold values used by only the function
the arguments are the values a function holds
func(1,2,3)
here 1,2,3 are arguments to (a,b,c) parameters ...when a function is called it can be called with or without an argument
attrubutes are larts of classes or methods
0
Thank you so much❤