Is this an example of python function overload?

后端 未结 3 1685
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 06:07

I know python does not allow us to overload functions. However, does it have inbuilt overloaded methods?

Consider this:

setattr(object_name,\'variable\',         


        
3条回答
  •  有刺的猬
    2021-01-29 06:32

    overloading methods is tricky in python. However, there could be usage of passing the dict, list or primitive variables.

    I have tried something for my use cases, this could help here to understand people to overload the methods.

    Let's take the example:

    a class overload method with call the methods from different class.

    def add_bullet(sprite=None, start=None, headto=None, spead=None, acceleration=None):

    pass the arguments from remote class:

    add_bullet(sprite = 'test', start=Yes,headto={'lat':10.6666,'long':10.6666},accelaration=10.6}

    OR add_bullet(sprite = 'test', start=Yes,headto={'lat':10.6666,'long':10.6666},speed=['10','20,'30']}

    So, handling is being achieved for list, Dictionary or primitive variables from method overloading.

    try it out for your codes

提交回复
热议问题