[python] How to use __command__, function explanation

A very personal note. Adding. Divide when it gets longer.

main

The name assigned to \ _ \ _ name \ _ \ _ when executed as a script

sample.py


    def main():
        print 'This function only run when that is main.'

    if __name__ == '__main__':
        main()

eq ne lt le gt ge

It means a function called Extended comparison. It is owned by all objects and is also called by the comparison operator. x> y andx.__gt__ (y)mean the same operation.

All six of these must be defined to define how objects are compared, In most cases, it is defined using a predefined comparison operation, so By total_ordering, one of [lt, le, gt, ge] and a total of two eq If you define The rest will be done automatically.

Quote: python documentation

total_ordering


@total_ordering
class Student:
    def __eq__(self, other):
        return ((self.lastname.lower(), self.firstname.lower()) ==
                (other.lastname.lower(), other.firstname.lower()))
    def __lt__(self, other):
        return ((self.lastname.lower(), self.firstname.lower()) <
                (other.lastname.lower(), other.firstname.lower()))

You use == in the definition of def __eq__ (self, other), that is, __eq__ Because <, that is, __lt __ is used in the definition statement ofdef __lt__ (self, other) The rest will do the same.

Recommended Posts

[python] How to use __command__, function explanation
How to use python zip function
python3: How to use bottle (2)
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use hash function and tuple.
[Python] How to use input ()
How to use Python with Jw_cad (Part 2 Command explanation and operation)
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
Python: How to use async with
How to use the zip function
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
How to use MBDyn (command setting)
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
[Python] How to use Typetalk API
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to install and use pandas_datareader [Python]
[Linux] How to use the echo command
How to calculate Use% of df command
How to use the Linux grep command
[Python] How to use import sys sys.argv
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
[Python2.7] Summary of how to use unittest
python: How to use locals () and globals ()
[Python / Tkinter] How to pass arguments to command
How to use __slots__ in Python class
How to use CUT command (with sample)
How to use "deque" for Python data
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
Summary of how to use Python list
How to use regular expressions in Python
[Python2.7] Summary of how to use subprocess
How to use is and == in Python
[Blender x Python] How to use modifiers
[Question] How to use plot_surface of python
[Python] Explains how to use the format function with an example
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to use Pandas 2