Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why python want us this : Non-default argument follows default argument

class Node():
    def __init__(self,value,parrent=None,neigh) -> None:
        self.val=value
        self.parrent=parrent
        self.neigh=neigh

Here I want to define a class. There is an error about neigh that non-default argument follows default argument. I saw the solution of this question but my main question is I want to know why python want us to do this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Because Python allows omission of keyword / default-specified parameters and allows passing parameters without explicitly naming them. If your definition was legal syntax (and the rest of the language functioned the same way), then instantiating

n = Node(4, 6)

might mean either

n = Node(value=4, parrent=6, neigh=None)

or

n = Node(value=4, parrent=None, neigh=6)

The point of syntax rules is to resolve ambiguities like this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading