Because your atribute is a class attribute:
class C:
ca = 123
print C.ca # 123
c1 = C()
print c1.ca# 123
c1.ca = 140
print c1.ca# 140
print C.ca # 123
c2 = C()
print c2.ca# 123
C.ca = 141
print C.ca # 141
print c1.ca# 140
print c2.ca
Andreas Kostyrka escribió:
Because your atribute is a class attribute:
class C:
ca = 123
print C.ca # 123
c1 = C()
print c1.ca# 123
c1.ca = 140
print c1.ca# 140
print C.ca # 123
c2 = C()
print c2.ca# 123
C.ca = 141
print C.ca #
I think I don't understand the OOP in python, could anyone explain why
this code works?
class example:
atribute = hello world
print example.atribute
Why you don't have to make an object of the class to access to the
atribute?
because that attribute is part of the Class
euoar [EMAIL PROTECTED] wrote in
Thank you for your answer and the examples.
So without self it is an instance variable (like static
in java/c#).
Without self it is a class attribute like static etc in C++/Java.
An instance variable is one that is unique to an instance!
Although I think
Alan Gauld wrote:
euoar [EMAIL PROTECTED] wrote in
So, in python, you can add methods at run time to an
object, and even you can add them to a class at run time?
I'm not sure about adding methods at run time, I've never
tried it but I think the magic around the self parameter
might not
Thank you folks, for your excellent answers. This is really a fantastic
place to learn python :-)
__
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
Kent Johnson [EMAIL PROTECTED] wrote
Alan Gauld wrote:
I'm not sure about adding methods at run time, I've never
Sure it works:
In [1]: class foo(object): pass
...:
In [4]: def show(self): print Hi, I'm a foo
In [5]: foo.show=show
In [6]: f.show()
Hi, I'm a foo
Cool!
I'm