+ 5

what is the difference between attribute, argument and parameter exactly?

11th Jul 2016, 8:04 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
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 ()
11th Jul 2016, 10:57 PM
Gershon Fosu
Gershon Fosu - avatar
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?
14th Jul 2016, 12:43 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
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.
14th Jul 2016, 12:47 PM
Gershon Fosu
Gershon Fosu - avatar
0
ooookeee. you helped me a lot!
14th Jul 2016, 12:50 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
Your welcome
14th Jul 2016, 12:53 PM
Gershon Fosu
Gershon Fosu - avatar
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
16th Apr 2019, 11:55 AM
Favour Kachi
Favour Kachi - avatar
0
Thank you so much❤
2nd Nov 2020, 11:55 AM
Am_ruta