You forgot to put the self in the method signature of main(). It should look like this
def main(self):
self.square(3)
Without that, self is in fact not defined in the scope of your method, so Python complains.
EDIT: also, as Some programmer dude mentions, your code never creates an instance of the class just executes main. There's also a problem with your indentation (probably a copy-paste error).
Try this instead:
class Back(object):
def square(self,x):
y = x * x
return y
def main():
back = Back()
print(back.square(3))
if __name__ == "__main__":
main()
notice how main is defined at the root level (it's not indented like square). It's not part of the class this way and doesn't need self. You could make it a method of the Back class again like this:
class Back(object):
def square(self,x):
y = x * x
return y
def main(self):
print(self.square(3))
if __name__ == "__main__":
back = Back()
back.main()
Ok, this last one, it doesn't really make sens to do it this way, I admit. But I'm just trying to illustrate scope and the difference between function and methods in python (I think this logic may help the OP more, considering the question).
selfobject as their first argument. It also doesn't make much sense to have themainfunction be a member function. And you never even create an instance (an object) of theBackclass. Lastly, for something simple like this, classes and objects doesn't really make much sense.