info about self

0 Vishak Raj · October 19, 2015
Why we use self and what happen when self is not use in the function
Help me to clarify this stuff...

Post a Reply

Replies

Oldest  Newest  Rating
0 sfolje 0 · October 22, 2015
self is 'used' in objects (read oop (read object-oriented-programing)). basicly long story for a post, but it could be any word really : Python doesn't treat word self any diffrently than other words- Its like, before you define a variable called variable1, python wouldn't know what the hack variable1 is, so it will cry a error. Once you define it, python will know what the variable1 is, so it will work fine.
But in spirit of saint programers they established a religion which says: use word 'self'. It is told to be usefull, when reading code, after a programmer understanging the code faster.
So you can use (i suppose you learned about objects and classes) any word instead of self and it will work, if it is not used in objects ("the function"), it will be not do anything or it will works as any other word.
  • 1

Python

107,004 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator