-1

I have no idea how python 2.7 works. Is there a way for me to convert it to python 3?

recipients = ['email@email.com', 'email2@email.com']
sent = 1
print 'Email sent to: %s (%s)' % (", ".join(recipients), sent)

Specifically, i'm unsure about the print statement.

NiKS
  • 377
  • 3
  • 15
Curio
  • 29
  • 6

1 Answers1

2

In Python 3, print is a function. So, you can make this work by changing it to:

recipients = ['email@email.com', 'email2@email.com']
sent = 1
print('Email sent to: %s (%s)' % (", ".join(recipients), sent))

But you can format using f-strings by changing your print statement like this:

print(f'Email sent to: {", ".join(recipients)}')

You can read more about f-strings here.

That's the only difference in this piece of code. You can read more about the changes here.

NiKS
  • 377
  • 3
  • 15
  • 1
    C-style string formatting is deprecated, it's better to use [f-strings](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) or [str.format](https://docs.python.org/3.8/library/stdtypes.html#str.format) function – Daniel Konovalenko Nov 15 '19 at 10:36
  • Hi @DanielKonovalenko: I've added an example using f strings as well. Thanks for reminding. – NiKS Nov 15 '19 at 10:40