guide plz why the output is not "fcim"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

guide plz why the output is not "fcim"?

def f(): print('f') class C: print('c') def __init__(self): print('i') def m(self): print('m') f() C().m()

22nd Jul 2020, 2:58 PM
Navneet
Navneet - avatar
1 Answer
+ 3
I think python firstly stores each function data in its memory and when we call it , it executes. As functions/method in oop are stored under class name. So in order to store that functions too it also go thru class and as it go thru it, it executes and print "c" first as it is not in any function/method. (I think)
22nd Jul 2020, 3:16 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar