What the last line for?


def spam():
eggs = 12
return eggs

print spam()

Checked the code above in http://pythontutor.com/visualize.html#mode=edit
but it shows that SyntaxError: invalid syntax (, line 5)
why? What's the spam() for?


In a Python 3 environment, print is a function so must take an argument.

print (spam())

This code will also work in Python 2 so if you feel like getting practice with Python 3 syntax, feel free. In most cases the SCT should be ignoring it, so only becomes a problem if the code is being pattern matched.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.