Python ActionScript 3 equivalent restParam

In ActionScript 3 (the Flash programming language is very similar to Java, to the extent that it interferes), if I defined a function and wanted it to be called with infinite parameters, I could do it (restParam, I thought it was called up):

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 using this :) annihilateUnicorns(new Unicorn(), new Unicorn(), new Unicorn(), new Unicorn());

It's nice that all these additional parameters are stored in an array. How do I do this in python? This clearly does not work:

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

Thanks !: D

+3
source share
1 answer
def annihilateUnicorns(*unicorns):
    for i in unicorns: # stored in a list
        i.splode()
    return "404 Unicorns not found. They sploded."
+4
source

Source: https://habr.com/ru/post/1767713/


All Articles