[python] class basic methods

I just added a little to help.

call(...)

python


x.__call__(...) <==> x(...)

Is it used when you want something to happen at the same time as the generation? The constructor is fine ...

delattr(...)

python


x.__delattr__('name') <==> del x.name

Set the action you want to take when you delete a class variable. You can also prevent it from being deleted.

eq ne ge gt le lt

python


x.__eq__(y) => x==y
x.__ne__(y) ==> x!=y
x.__ge__(y) => x>=y
x.__gt__(y) => x>y
x.__le__(y) => x<=y
x.__lt__(y) => x<y

Behavior when using a comparison operator. It is easier to use [total_ordering] link-1 when setting. I use this a lot.

getattribute(...)

python


x.__getattribute__('name') => x.name

You can change the behavior when a class variable is called directly.

init(...)

Needless to say. constructor.

instancecheck(...)

__instancecheck__() -> bool

I don't understand the behavior. Even if I set it and do is in satnce, it is not reflected. If anyone knows, please let me know.

repr(...)

x.__repr__() => repr(x)

If you have str, you won't use it much.

setattr(...)

x.__setattr__('name', value) <==> x.name = value

It's a method of defining class variables from outside the class. For example, you can limit this or register with a different name. Or you can assign another instance created based on value to x.name. It seems that it can be used in various ways.

subclasscheck(...)

__subclasscheck__() -> bool

I'm not sure about this either. Even if it is set, the behavior does not change.

subclasses(...)

__subclasses__() -> list of immediate subclasses

What is this too? I tried calling dic .__ subclasses __ ()

print(dic.__subclasses__())


[<type 'collections.defaultdict'>, <class 'collections.OrderedDict'>, <class 'collections.Counter'>, <class 'traitlets.config.loader.Config'>, <class 'IPython.utils.ipstruct.Struct'>, <class 'IPython.utils.coloransi.ColorSchemeTable'>, <class 'plistlib._InternalDict'>, <class 'pkg_resources.ZipManifests'>, <type 'StgDict'>]

nonzero(...)

Set the behavior when the instance itself is used for bool judgment. The default is all True. Or whether len () has a value of 1 or greater.

len(...)

x.__len__() => len(x)

Shows the behavior when called by len (). If nonzero () is not set, bool is judged by this value. True if neither is set

Recommended Posts

[python] class basic methods
[Python] class, instance
RF Python Basic_01
"Kanrika" python class
About python, class
Basic Python writing
Python3 basic grammar
Python class, instance
RF Python Basic_02
#Python basics (class)
Python basic operation 3rd: Object-oriented and class
python syslog wrapper class
Python basic course (12 functions)
Python I'm also basic
Python class (Python learning memo ⑦)
Python basic grammar / algorithm
Python basic course (2 Python installation)
case class in python
Basic sorting in Python
Convenient Python methods, etc.
Python basic course (9 iterations)
[Python] Class inheritance (super)
Python self-made class sort
Python Basic Course (11 exceptions)
[Python] Class inheritance, override
Python basic course (6 sets)
Python3 cheat sheet (basic)
Python basic grammar (miscellaneous)
Python Basic Course (Introduction)
Python basic memorandum part 2
python subprocess wrapper class
python basic on windows ②
Python basic memo --Part 2
Python basic course (13 classes)
Basic Python command memo
Class methods and static methods
Python basic grammar note (4)
Python basic grammar note (3)
Basic knowledge of Python
Python basic grammar memo
OpenCV basic code (python)
Python basic memo --Part 1
YOLO Python wrapper class
Class notation in Python
Python exception class list
python memorandum super basic
Python basic course (8 branches)
Python basic if statement
Python Basic Course (3 Python Execution)
Python Basic --Pandas, Numpy-
Basic Python 3 grammar (some Python iterations)
Various class methods and static methods
Python application: Pandas Part 1: Basic
Refactoring Learned in Python (Basic)
BASIC authentication with Python bottle
String object methods in Python
C / C ++ programmer challenges Python (class)
Python basic dict sort order
[Python] Using OpenCV with Python (Basic)
Python basic course (10 inclusion notation)
Python installation and basic grammar