Can I use the variable name “type” as function argument in Python?

前端 未结 5 1494
别那么骄傲
别那么骄傲 2020-12-07 00:44

Can I use type as a name for a python function argument?

def fun(name, type):
    ....
5条回答
  •  旧巷少年郎
    2020-12-07 01:08

    You can, and that's fine. Even though the advice not to shadow builtins is important, it applies more strongly if an identifier is common, as it will increase confusion and collision. It does not appear type will cause confusion here (but you'll know about that more than anyone else), and I could use exactly what you have.

提交回复
热议问题