攝影或3C

Python 具有強制特性的函式庫規格化; from multipledispatch import dispatch

 

 

from multipledispatch import dispatch
# import multipledispatch as dispatch #這行不對
@dispatch(float, float)
def myFunc(a: float, b: float) -> float:
  ret = a + b
  return ret
print(myFunc(1, 2))

#強制使用浮點數,

#報NotImplementedError
#改為1.0 , 2.0即可執行

 

typing可以使用Union

但dispatch不行,

會出現TypeError

Traceback (most recent call last):
File “c:\Python\RF Stable\untitled0.py”, line 7, in <module>
def myFunc(a: Union[float, int], b: Union[float, int]) -> Union[float, int]:
File “C:\ProgramData\Anaconda\lib\site-packages\multipledispatch\core.py”, line 68, in _
dispatcher.add(types, func)
File “C:\ProgramData\Anaconda\lib\site-packages\multipledispatch\dispatcher.py”, line 222, in add
raise TypeError(“Tried to dispatch on non-type: %s\n”
TypeError: Tried to dispatch on non-type: typing.Union[float, int]
In signature: <typing.Union[float, int], typing.Union[float, int]>
In function: myFunc

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡