Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
*args and Tuples
#1
def func(*items):
     print(type(items)) 
     a=list(items)
     print(type(a))
     a[3]= 1026
     for i in a:
         print i

items=[1,3,7,9,-99,555,88]
func(*items[:]) 
I am trying to pass a list into *args(*items) and it insists on unpacking it into a tuple, whose immutability makes manipulation of data nigh impossible without converting it into a list.

In all examples I see the default usage of *args is to print, or do some things fairly useless. Being new, I might have overlooked something blazingly obvious - which is why I put this question here:

Is conversion to tuple in *args functions default behaviour for list(array) arguments?
And is there a simple way to call variable arguments and have them default to mutable data types? A decorator?
Reply


Messages In This Thread
*args and Tuples - by millpond - Aug-22-2019, 04:22 AM
RE: *args and Tuples - by Gribouillis - Aug-22-2019, 05:04 AM
RE: *args and Tuples - by millpond - Aug-22-2019, 07:44 AM
RE: *args and Tuples - by Gribouillis - Aug-22-2019, 07:59 AM
RE: *args and Tuples - by joe_momma - Dec-15-2019, 05:54 PM

Forum Jump:

User Panel Messages

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