0

I'am making my first steps with Python. I have written very simple program, yet it is not working. The error messege is: NameError: name 'fun' is not defined.
I'm using Spyder and Python 3.7.

class myClass(object):
    def __init__(self):
        self.a = fun()

    def fun(self):
        return 10

instance = myClass()
Patrick Haugh
  • 55,247
  • 13
  • 83
  • 91
Karol Borkowski
  • 318
  • 2
  • 16

1 Answers1

2

Instead of self.a=fun() use self.a=self.fun() then only it will become clear to interpreter as to which fun() you are referring to.

KTDLIN
  • 21
  • 3