-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
  • 353,842
  • 52
  • 662
  • 667
Underoos
  • 3,734
  • 6
  • 30
  • 63

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
  • 491,798
  • 79
  • 706
  • 853