+ 1
What is the difference between an attribute and a property?
7 ответов
+ 2
From courses:
"parameter is a named enntity in a function(or method) definition that specifies an argument that the function can accept"
"Instance of a class have attributes, which are pieces of data associated with them"
and example:
class Dog:
def __init__(self, name, color):
self.name = name
self.color = color
def bark(self):
print("Woof!")
fido = Dog("Fido", "brown")
print(fido.name)
fido.bark()
in this example you created object fido (it's parameter for class Dog, and if you want call method of this class you use "fido" - for example fido.bark) class Dog with two attributes - name and color.
Another word, "self." it's parameter "name", "color" it's attribute.
+ 1
It seems properties are a special kind of attribute
+ 1
@Marek, thanks, but I didn't ask about parameters, I asked about properties, which I don't think are the same thing.
+ 1
I think that attribute is the same property.
attribute or property are instamce of a class
example class car {
var color:string // attribute or property color
var type:int // attribute or property type
}
+ 1
attributes can be changed but property is not change.