views:

21

answers:

1

In ActionScript 3 (Flash's programming language, very similar to Java - to the point that it's disturbing), if I was defining a function and wanted it to be called with endless parameters, I could do this (restParam, I thought it was called):

function annihilateUnicorns(...unicorns):String {
    for(var i:int = 0; i<unicorns.length; i++) {
        unicorns[i].splode();
    }
    return "404 Unicorns not found. They sploded.";
}

(then you could call it with this:) annihilateUnicorns(new Unicorn(), new Unicorn(), new Unicorn(), new Unicorn());

What's cool is that all of those extra parameters are stored in an array. How would I do that in python? This obviously doesn't work:

def annihilateUnicorns (...unicorns):
    for i in unicorns :
        i.splode()
    return "404 Unicorns not found. They sploded."

Thanks! :D

+2  A: 
def annihilateUnicorns(*unicorns):
    for i in unicorns: # stored in a list
        i.splode()
    return "404 Unicorns not found. They sploded."
THC4k
Thanks! That's exactly what I wanted!
UncleNinja