Python notes using perl-special variables

--Make a note of what you thought was python.

This kind of → \ _ \ _ name \ _ \ _

――Perl is also called a mysterious language because it has various special variables such as $ _, but the promised keywords in any language are confusing at first. I think this is the first thing you notice.

if __name__ == '__main__':

Underscore is special in the first place

--There was an explanation in Japanese. Reserved identifier species --Explanation of the head family. Reserved classes of identifiers

--Try some of the two underscores (\ _ \ _ xxx \ _ \ _) used in the system.

  1. __name__

--When executed by a script, it becomes'\ _ \ _ main \ _ \ _', and when called from a module, it becomes the module name, and when called from a function, it becomes the function name.

>>> __name__
'__main__'
>>> def hoge():
...     print(u'hello')
... 
>>> hoge.__name__
'hoge'
  1. \ _ \ _ init \ _ \ _

――It comes out in the definition of the class.

>>> class MyClass:
...     def __init__(self):
...             self.name = "anonymous"
... 
>>> a = MyClass()
>>> a.name
'anonymous'

-Special method name also has various explanations. If you remember this exactly, development will go smoothly.

Even with objective-c ...

--It is also objective-c to add \ _ in the member variable. --Don't access member variables directly with underscores! Does that mean almost the same?

Recommended Posts

Python notes using perl-special variables
Notes using Python subprocesses
# 1 [python3] Simple calculation using variables
[Python] Variables
Initializing global variables using Python decorators
Notes on using MeCab from Python
Using global variables in python functions
Notes on installing Python using PyEnv
Notes on using rstrip with python.
Notes for using OpenCV on Windows10 Python 3.8.3.
Python scraping notes
Notes using cChardet and python3-chardet in Python 3.3.1.
Python study notes _000
Python beginner notes
Python study notes_006
Start using Python
python C ++ notes
Python study notes _005
Python grammar notes
Python Library notes
Notes for using python (pydev) in eclipse
python personal notes
Scraping using Python
Notes on using code formatter in Python
python pandas notes
Python study notes_001
python learning notes
Python3.4 installation notes
Notes on using dict in python [Competition Pro]
[Python] Notes on accelerating genetic algorithms using multiprocessing
Python memorandum numbering variables
[Python] Get environment variables
Operate Redmine using Python Redmine
missingintegers python personal notes
Fibonacci sequence using Python
Data analysis using Python 0
Python package development notes
Data cleaning using Python
python decorator usage notes
Python ipaddress package notes
[Personal notes] Python, Django
Using Python #external packages
Python Pickle format notes
WiringPi-SPI communication using Python
[Python] pytest-mock Usage notes
First Python miscellaneous notes
Age calculation using python
Matlab => Python migration notes
Search Twitter using Python
Notes around Python3 assignments
Name identification using python
Notes on using Alembic
Try using Tweepy [Python2.7]
Python try / except notes
Python framework bottle notes
Minimum notes when using Python on Mac (Homebrew edition)
Flatten using Python yield from
Scraping using Python 3.5 async / await
Environment variables when using Tkinter
Save images using python3 requests
Python: Class and instance variables