1. The pass statement does not do anything. It is generally used as a placeholder or creates a placeholder program. The pass statement does not perform any operations, for example:
While false:
Pass
Pass is usually used to create the simplest class:
Class myemptyclass:
Pass
In the software design phase, pass is often used as a todo to remind you to implement the corresponding implementation. For example:
Def initlog (* ARGs ):
Pass # Please implement this
Take the if statement as an example,
In C or C ++/Java:
If (true)
; // Do nothing
Else
{
// Do something
}
For python, write as follows:
If true:
Pass # do nothing
Else:
# Do something
2. _ init _ usage
_ Init _ is automatically called when the class is initialized to complete initialization of the object, for example:
Class person:
Def _ init _ (self, name ):
Self. Name = Name
Def sayhi (Self ):
Print 'hello, my name is ', self. Name
P = person ('swaroop ')
P. sayhi ()
Running result:
Hello, my name is swaroop
We can see from the results that although we do not display the call _ init _ method, the class person is still initialized.
3. _ name _ usage
If a. py file is run independently, _ name _ is set to _ main _, so you can use
If _ name __= = '_ main _': To make some judgments,
However, if the. py file is imported as a module, _ name _ Is Not _ main _ and will be set as the module name, for example:
>>> Import odbchelper
>>> Odbchelper. _ name __
'Oddbchelper'