+ 2

Self

what is self in classes. and why should self be the first parameter of every classes. and what is its importance. thank you

15th Mar 2017, 5:55 PM
stephen haokip
stephen haokip - avatar
3 odpowiedzi
+ 10
See SoloLearn's Python course > Object oriented programming > Class, lesson 2: 'All methods must have self as their first it isn't explicitly passed, Python adds the self argument to the list for you; you do not need to include it when you call the methods. Within a method definition, self refers to the instance calling the method.'
15th Mar 2017, 6:39 PM
Tashi N
Tashi N - avatar
+ 6
Tashi N explained it very well. self is like 'this' in other programming languages.
15th Mar 2017, 8:45 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Because self is the class itself, any class should access to itself
18th Mar 2017, 5:15 AM
Mohammad Ebrahimi
Mohammad Ebrahimi - avatar