Python Forum
How to access arguments by name from function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access arguments by name from function
#1
Hi,

I have function in which I am passing multiple lists. Now, I want to access (or assign to another variable) the lists (given as arguments in function) by its name. I tried below code, but its giving error.

#%% passing multiple lsit to function
def my_func(list1,list2,list3):
    return list1,list2,list3
p1 = my_func(list1 = ['BNKL', 'KPUI', 'HYNI'],\
             list2 = ['Ty'],\
                  list3 = [6, 7, 8])
print(" The first list : ", p1[0])
print(" The second list : ", p1[list1])
l_l1 = p1[1]
Error:

The first list :  ['BNKL', 'KPUI', 'HYNI']
Traceback (most recent call last):

  File "<ipython-input-2-30d2f38dbdd7>", line 6, in <module>
    print(" The second list : ", p1[list1])

NameError: name 'list1' is not defined
Reply


Messages In This Thread
How to access arguments by name from function - by SriRajesh - Sep-19-2019, 01:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  calling external function with arguments Wimpy_Wellington 7 1,451 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  'namespace' shorthand for function arguments? shadowphile 5 2,608 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  Checking the number of arguments a function takes Chirumer 3 2,165 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Possible to dynamically pass arguments to a function? grimm1111 2 2,201 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  How to pass multiple arguments into function Mekala 4 2,463 Jul-11-2020, 07:03 AM
Last Post: Mekala
  How to give a name to function arguments in C-API? WonszZeczny 0 1,350 Jun-22-2020, 10:20 AM
Last Post: WonszZeczny
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,254 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  Pass Arguments to Function phillyfa 2 2,031 Mar-27-2020, 12:05 PM
Last Post: phillyfa
  Function with many arguments, with some default values medatib531 3 2,607 Mar-14-2020, 02:39 AM
Last Post: medatib531
  Using function *args to multiply multiple arguments allusernametaken 8 6,101 Nov-20-2019, 12:01 AM
Last Post: allusernametaken

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020