我有一個函數,應該根據傳入它的參數類型進行操作,簡單說明:def operate_according_to_type(argument_passed): if type(argument_passed) == str: do string stuff elif type(argument_passed) == dict: do dict stuff elif type(argument_passed) == function: argument_passed()def my_function(): passoperate_according_to_type("Hello world")operate_according_to_type({"foo": "bar"})operate_according_to_type(my_function)現在,雖然 ,并且將分別返回,并且,我似乎無法與我能比較的,這個詞甚至不是“保留”。type("Hello world")type({"foo": "bar"})type(my_function)<class 'str'><class 'dict'><class 'function'>functionstr我應該如何繼續?我應該繼續還是這只是危險的?
添加回答
舉報
0/150
提交
取消