-1

I know that the print is a function in Python 3 and a statement in Python 2. Found it here

I tested local and online interpreters with below code

In Python 3:

print('test') - working fine

print 'test' - throwing error

In Python 2:

print('test') - working fine

print 'test' - working fine

My question is that if the print is a statement and not a function in Python 2, isn't it supposed to throw a syntax error when we use print function?

Why is it still working in Python 2 when we use print function?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Underoos
  • 4,708
  • 8
  • 42
  • 85

1 Answers1

2

('test') is a valid expression in any version of Python; the parentheses just act as a grouping for multiple expressions, of which there's only one here, so they're superfluous.

print('test') in Python 2 is the same as print ('test') is the same as print (('test')) is the same as print 'test'.

deceze
  • 510,633
  • 85
  • 743
  • 889