• Register

This blunder may occur in the event that you typedef _init_ with a solitary underline rather than def __init__ with twofold underlines when init. 

It implies that each time an object of the class is made, the constructer is called. This constructor doesn't acknowledge any factors or capacities as its boundary. In layman's words, the constructor will have nothing inside its enclosures with the exception of the self watchword. Model: class my_class: def __init__(self): #constructor code goes here Here,the constructor __init__ takes no contentions. 

Called after the example has been made (by new()), however before it is gotten back to the guest. The contentions are those passed to the class constructor articulation. In the event that a base class has an init() strategy, the inferred class' init() technique, assuming any, must unequivocally call it to guarantee legitimate instatement of the base class part of the occasion; for instance: super().init([args...]). Since new() and init() cooperate in developing articles (new() to make it, and init() to modify it), no non-None worth might be returned by init(); doing so will make a TypeError be raised at runtime. 

We have two sorts of Constructor in python: 

• default constructor: which is utilized when you don't proclaim the defined constructor. its definition has just a single contention which is a reference to the example being built (a.k.a self). 

def __init__(self): 

# default constructor 

• parameterized constructor: which takes different boundaries notwithstanding the self boundary. 

def __init__(self, boundaries): 

# defined constructor 

on the off chance that you don't pronounce a defined constructor, python utilizes the default constructor which doesn't take any boundary. So you passed a contention to the default constructor and the special case has been tossed. 

How to fix it? 

Simply announce a defined constructor by which you can launch your occurrences.


class Person: 

def __init__(self, name): 

self.name = name


    def __init__(self, start):

        self.num = start

    def __iter__(self):

        return self

    def __next__(self): // This will go to infinity but you can applyyour own logic to

        num = self.num

        self.num += 1

        return num

Calling can be done by two format either this.

>>> c = Count()

>>> next(c)


Or this:

>>> for n in Count():

...     print(n)

Kindly share and like the post if you liked it, Happy coding from Kodlogs.


Interesting!. Thank you for posting
Your welcome

More Posts

How to fix C# Error Class does not contain a constructor that takes 0 arguments mhfaisal - May 5
no operator found which takes a right-hand operand of type Lalit Kumar - Aug 14, 2020
What does slice do with no arguments? Lalit Kumar - Oct 9, 2020
Python attributeerror: 'module' object has no attribute amna - May 24
Modulenotfounderror: no module named 'pygame' Abhay Kumar Prajapat - Jun 19, 2020
No enclosing instance of type is accessible. Tania - Jan 31
If you forget to put a closing quotation mark on a string, what kind of error will be raised? Farkhanda Athar - Apr 11, 2020
What does a percent sign mean in python Tania - May 27
What is Python? maazmasood - Apr 19
What is the difference between function and method amna - Mar 17