Let's say I have a base class in Python 3, which is some type of data type data type. I want to do this when I have an instance x of this class, I can call int (x) and call its conversion function to return the integer part.
I am sure it is simple, but I cannot figure out how to do it.
You are redefining the __int__ magic method according to the example below ...
__int__
class Test: def __init__(self, i): self.i = i def __int__(self): return self.i * 2 t = Test(5) print( int(t) ) # 10
Cancel the __int__() method.
__int__()
Source: https://habr.com/ru/post/920944/More articles:Symfony 2 lesscss paths - lessHow to recognize touches by uisegmentedcontrol - even on a selected segment? - iosStepping Through (F8) Does the code suddenly execute all the code? - vbaHow to specify the minimum perl version for my distribution in Dist :: Zilla dist.ini? - perlAwk multiline comment - awkFailed to start distributed transaction: Linked Server -> Access database - sql-server-2008Why are Mojolicious nesting my routes? - perlCan I specify a path in git whose name depends on the operating system - gitEclipse - create new activity - androidCounting changes in history using MySQL - mysqlAll Articles