5

Very Quick Question. I have a print function that looks like the statement below:

print(*Runner(x,y))

What is the * for in this case? I have no clue what it does in this context.

miken32
  • 42,008
  • 16
  • 111
  • 154
shurburt
  • 93
  • 2
  • 6
  • What happened when you ran that code. What was your output? The single asterisk in that case you provided will unpack the values. – idjaw Mar 12 '16 at 05:29
  • TypeError: print() argument after * must be a sequence, not NoneType – shurburt Mar 12 '16 at 05:30
  • OK. So next question. Why are you using it? What are you trying to do exactly? – idjaw Mar 12 '16 at 05:31
  • Its an assignment. I've done some research but it hasn't helped me understand what it does exactly. So, I'm reaching out the OverFlow community. – shurburt Mar 12 '16 at 05:33
  • 3
    `Runner(x,y)` returns a list or tuple. The `*` unpacks that list / tuple, passing each element from the list / tuple as a separate argument to the `print` function. See [Unpacking Argument Lists](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists) in the Python docs and the answers in [my link](http://stackoverflow.com/questions/16515443/what-does-the-asterisk-do-in-python-other-than-multiplication-and-exponentiation) for further details. – PM 2Ring Mar 12 '16 at 05:34
  • Ok that makes some since. Thank you. – shurburt Mar 12 '16 at 05:37

0 Answers0