-4

I am receiving AttributeError: 'Test' object has no attribute 'a'. I don't understand what is wrong with the code. Please advise.

class Test():
    def __int__(self):
        self.a = 1

t = Test()
print(t.a)
  • 2
    Its `__init__` not `__int__`. – xilpex May 13 '20 at 01:23
  • Does this answer your question? [AttributeError: 'module' object has no attribute 'tests'](https://stackoverflow.com/questions/25575073/attributeerror-module-object-has-no-attribute-tests) – Diggy. May 13 '20 at 01:23
  • Hi, welcome to StackOverflow! Please go through guidelines before asking - https://stackoverflow.com/help/how-to-ask – Harshit May 13 '20 at 01:24

1 Answers1

0

It should be init (short for initialise), not int (integer):

class Test():
    # here was the fault
    def __init__(self):
        self.a = 1

t = Test()
print(t.a)
# Outputs 1

You defined the wrong method

Banana
  • 2,295
  • 1
  • 8
  • 25