Accessing a value in a method using *

In a method definition, when *

used like this, what does it mean?

def foo(*)


I understand the following usage:

def foo(*args)


I'm not sure how to access the method parameters in the first case.


source to share

2 answers

This means "accept and discard any number of parameters."

Both definitions are technically the same, but without specifying the name of the argument array, you cannot access it.



In the first case, it simply allows the call with arbitrary arguments and discards them.

The second case assigns any arguments to args



All Articles