Way to pass multiple parameters to a function in python

前端 未结 6 1765
遇见更好的自我
遇见更好的自我 2021-02-06 09:12

I have written a python script which calls a function. This function takes 7 list as parameters inside the function, something like this:

def WorkDetails(link, A         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 09:35

    You could use *args if you don't need to use names for your lists:

    def WorkDetails(link, *args):
        if args[0] == ... # Same as if AllcurrValFound_bse == ...
            ...
    
     # Call the function:
     WorkDetails(link, AllcurrValFound_bse, AllyearlyHLFound_bse, AlldaysHLFound_bse, AllvolumeFound_bse, AllprevCloseFound_bse, AllchangePercentFound_bse, AllmarketCapFound_bs)
    

    Or you could use a dictionary

    def WorkDetails(link, dict_of_lists):
        if dict_of_lists["AllcurrValFound_bse"] == ...
            ...
    
    # Call the function
    myLists = {
        "AllcurrValFound_bse": AllcurrValFound_bse,
        "AllyearlyHLFound_bse": AllyearlyHLFound_bse,
        ...,
        ...
    }
    WorkDetails(link, myLists)
    

提交回复
热议问题