self parameter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

self parameter

I want to know about self parameter in class in broader way. Can anyone tell me. Why we use self in Python and not in other languages ?

8th Feb 2022, 5:21 PM
Mahesh Umale
Mahesh Umale - avatar
1 Answer
+ 2
Richard Newman self behaves like this (java) but remember self is not a keyword, you can change self to this also. class Circle (object): def __init__(self, radius): self.radius = radius circle1 = Circle (10) change self to this: class Circle (object): def __init__(this, radius): this.radius = radius circle1 = Circle (10) in Java: class Circle { private int radius; public Circle (int radius) { this.radius = radius; } } Circle c = new Circle (10);
8th Feb 2022, 5:34 PM
A͢J
A͢J - avatar