types and objects behavior can be enabled in python as an optional feature by including the statement from _future_ import division in program the conversion methods _int_ () _long_ () _float_ ()and _complex_ (convert an object into one of the four built-in numerical types these methods are invoked by explicit type conversions such as int(and float(howeverthese methods are not used to implicitly coerce types in mathematical operations for examplethe expression produces typeerror even if is userdefined object that defines _int_ (for integer conversion callable interface an object can emulate function by providing the _call_ (self [,*args [**kwargs]]method if an objectxprovides this methodit can be invoked like function that isx(arg arg invokes _call_ (selfarg arg objects that emulate functions can be useful for creating functors or proxies here is simple exampleclass distancefrom(object)def _init_ (self,origin)self origin origin def _call_ (selfx)return abs( self originnums [ - nums sort(key=distancefrom( )sort by distance from in this examplethe distancefrom class creates instances that emulate singleargument function these can be used in place of normal function--for instancein the call to sort(in the example context management protocol the with statement allows sequence of statements to execute under the control of another object known as context manager the general syntax is as followswith context as var]statements the context object shown here is expected to implement the methods shown in table the _enter_ (method is invoked when the with statement executes the value returned by this method is placed into the variable specified with the optional as var specifier the _exit_ (method is called as soon as control-flow leaves from the block of statements associated with the with statement as arguments_ _exit_ (receives the current exception typevalueand traceback if an exception has been raised if no errors are being handledall three values are set to none table special methods for context managers method description _enter_ (selfcalled when entering new context the return value is placed in the variable listed with the as specifier to the with statement lib fl ff