-6

Is the print syntax in v2.7 not compatible in v3.4?

i remember being told not that

print 0.3

won't work.

And i learned

print '%f' % 1/3

Now in v3.4 here's what happened:

print(1/3)

output: 0.3333333333333333

print `'%f' % 1/3`

output: SyntaxError: invalid syntax

print('%3.3f" % 1/3)

output: SyntaxError: EOL while scanning string literal

print('%(number)3.3f' % {'number':1/3})

output: 0.333

Let me know. Thanks

Paul H
  • 65,268
  • 20
  • 159
  • 136
XYZ
  • 105
  • 2
  • 9

2 Answers2

0

print('%3.3f" % 1/3)

You start with a single quote and finish with a double quote

print('%3.3f' % 1/3) or print("%3.3f" % 1/3) will work just fine

Paul H
  • 65,268
  • 20
  • 159
  • 136
0

Yes the syntax changed. Look at https://docs.python.org/3.0/whatsnew/3.0.html for closer information. Although the formatted print statements still work. You just have a typo there. (biggest difference are the parentheses, 3.x requires them 2.7 does not)

Daniel Kogan
  • 235
  • 1
  • 6