How do I create class attributes in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do I create class attributes in Python?

I wanted to create a class attributes, that doesn't belong to the class objects (static attributes), how can I do that?

30th Oct 2019, 7:18 AM
Seb TheS
Seb TheS - avatar
3 Answers
+ 4
The beginning of your code can be like this: class Myclass: Attribute1 = value1 Attribute2 = value2 def __ init__(self): ...
30th Oct 2019, 8:21 AM
Qasem
+ 2
Seb TheS you can achieve that by magic methods like this code: https://code.sololearn.com/cLpCdHaqlb0d/?ref=app
30th Oct 2019, 10:54 AM
Qasem
0
@Qasem Yes, but I don't want those attributes to be shared with the objects
30th Oct 2019, 10:16 AM
Seb TheS
Seb TheS - avatar