आप सही है, हालांकि आप इसे वैश्विक फोन नहीं होगा क्या है, यह एक वर्ग विशेषता है और पहुँचा जा सकता है वर्ग के माध्यम से Shape.lolwut
या उदाहरण के माध्यम से उदाहरण के लिए shape.lolwut
लेकिन जब यह स्थापित करने के रूप में यह एक उदाहरण स्तर सेट हो जाएगा सावधान रहना वर्ग विशेषता नहीं विशेषता
class Shape(object):
lolwut = 1
shape = Shape()
print Shape.lolwut,
print shape.lolwut,
# setting shape.lolwut would not change class attribute lolwut
# but will create it in the instance
shape.lolwut = 2
print Shape.lolwut,
print shape.lolwut,
# to change class attribute access it via class
Shape.lolwut = 3
print Shape.lolwut,
print shape.lolwut
उत्पादन:
1 1 1 2 3 2
किसी ने उत्पादन 1 1 2 2 3 3
होने की उम्मीद कर सकते हैं, लेकिन यह सही नहीं होगा और
स्रोत
2011-06-25 02:05:51
हैं नीचे दिए गए उत्तर को आपको – Clintm