Class based confusion | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Class based confusion

Class GM: Object={} Class_n='' def __init__(self,name): Gm.Object[Class_n]=self ----------------------------------------- What does this "Gm.Object[Class_n]=self" mean what is self? What will be the Object after this code?

23rd May 2020, 11:12 AM
Akshaya Shankar
Akshaya Shankar - avatar
1 Answer
0
class GM: Object={} Class_n='' def __init__(self,name): print("self:",self) print("type of self:",type(self)) GM.Object[GM.Class_n]=self t = GM("query") print(GM.Object['']) #self is GM class instance. GM.Object[GM.Class_n]=self here you are creating dictionary named Object and store the GM instance as value for the key Class_n=''. Try to run above code and get it clarify.
23rd May 2020, 7:36 PM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar