Search code examples
pythonprintingpython-3.xsyntax-error

Why is this invalid syntax?


Why is this complaining about an invalid syntax?

#! /usr/bin/python

recipients = []
recipients.append('me@example.com')

for recip in recipients:
    print recip

I keep getting:

File "send_test_email.py", line 31
    print recip
              ^
SyntaxError: invalid syntax

Solution

  • If you are using Python 3 print is a function. Call it like this: print(recip).