New answers tagged instance
0 votes
Is there a way in a class function to return an instance of the class itself?
I had exactly this problem today and found that this works: from __future__ import annotations class a(type): def __init__(self, n): self.n = n def foo() -> a: return a(...
Top 50 recent answers are included
Related Tags
instance × 5912class × 1480
python × 1079
java × 1073
c# × 609
object × 587
oop × 333
methods × 310
javascript × 309
c++ × 263
android × 249
variables × 232
static × 208
php × 206
haskell × 171
constructor × 162
arrays × 148
amazon-web-services × 141
inheritance × 138
python-3.x × 136
ruby × 133
list × 117
objective-c × 114
singleton × 111
amazon-ec2 × 110