The meaning of self

Without self, it becomes indistinguishable from local variables (variables initialized inside the function).

class Sample:
    num = 100
    def show_num(self):
        num = 200
        print(self.num)
        print(num)
        
a= Sample()
a.show_num()

The output is as follows

>>>100
>>>200

It means that there is a good distinction between print (self.num) and print (num).

Recommended Posts

The meaning of self
The meaning of ".object" in Django
The beginning of cif2cell
The meaning of {version-number} in the mysql rpm package
Organize the meaning of methods, classes and objects
the zen of Python
Meaning of Linux permissions
The story of sys.path.append ()
Revenge of the Types: Revenge of types
Why is the first argument of [Python] Class self?
Scraping the result of "Schedule-kun"
The story of building Zabbix 4.4
Towards the retirement of Python2
[Apache] The story of prefork
Compare the fonts of jupyter-themes
About the ease of Python
Get the number of digits
Explain the code of Tensorflow_in_ROS
Reuse the results of clustering
GoPiGo3 of the old man
Calculate the number of changes
Change the theme of Jupyter
The popularity of programming languages
Change the style of matplotlib
Visualize the orbit of Hayabusa2
About the components of Luigi
Connected components of the graph
Filter the output of tracemalloc
About the features of Python
Simulation of the contents of the wallet
The Power of Pandas: Python
Meaning of Linux directory permissions
Different from the import type of python. from A import B meaning
Understanding the meaning of complex and bizarre normal distribution formulas
The specifications of pytz have changed
Find the definition of the value of errno
The day of docker run (note)
Plot the spread of the new coronavirus
The story of Python and the story of NaN
Raise the version of pyenv itself
Get the number of views of Qiita
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Japanese translation of the e2fsprogs manual
Change the background of Ubuntu (GNOME)
Is the probability of precipitation correct?
I investigated the mechanism of flask-login!
Understand the contents of sklearn's pipeline
The world of control engineering books
Step into the darkness of msync
Take the execution log of Celery
Test the goodness of fit of the distribution
Existence from the viewpoint of Python
Calculation of the number of Klamer correlations
pyenv-change the python version of virtualenv
About the return value of pthread_mutex_init ()
Combine the overlap of one-dimensional intervals
Get the attributes of an object
Solve the delay of interferometer observation
Distinguishing the agari shape of mahjong
Python-Simulation of the Epidemic Model (Kermack-McKendrick Model)