0
Can we create class in function?
Function, class
2 ответов
+ 4
Usually no, it is not possible to create classes inside functions, but it may also depend on the programming language, which you did not specify.
"confuse" is not a language, please use correct tags.
0
Bhagwat Manwatkar ,
Please add a tag for the language you're asking about, or give more info.
It's possible in Python. I just verified it, but I haven't explored it.
def f():
class C:
def __init__(self, a):
self.a = a
return C
x = f()(10)
print(x.a) # 10