To add to the Getter & Setter examples: You can use this in Python instead of self. It is just a convention, that people refer to the current instance as self. Also, instead of sqrt in both languages, you can write **0.5. With both modifications, that codes look even more similar.
About the classes example: They might look similar, but they are not. __init__ is not a constructor. __init__ is an initializer. The constructor in Python is called __new__. Also, usually you override __repr__ to get a representation of the object instead of __str__.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
To add to the Getter & Setter examples: You can use
this
in Python instead ofself
. It is just a convention, that people refer to the current instance asself
. Also, instead ofsqrt
in both languages, you can write**0.5
. With both modifications, that codes look even more similar.About the classes example: They might look similar, but they are not.
__init__
is not a constructor.__init__
is an initializer. The constructor in Python is called__new__
. Also, usually you override__repr__
to get a representation of the object instead of__str__
.