I am out of trial and error again Lists

Rustom Mody rustompmody at gmail.com
Sat Oct 25 07:40:33 CEST 2014


On Saturday, October 25, 2014 9:56:02 AM UTC+5:30, Ben Finney wrote:
> Rustom Mody writes:
> 
> > On Saturday, October 25, 2014 9:17:12 AM UTC+5:30, Rustom Mody wrote:
> > > 4. The least useful statement to try at the interpreter is print.
> >
> > Yeah this is python2 thinking; in python 3, print is technically an
> > expression.
> 
> This is wrong thinking. In Python 3, print is a function.

[tl;dr at bottom]

Ok I was a bit sloppy -- should have said 'the print'
But there was no specific prior use that 'the' would refer to.
So one could say (if you like!):

|          | Python 2  | Python 3   |
| print    | syntax    | function   |
| print(x) | statement | expression |

I was really talking of the second row not the first

So much for being legalistic -- An approach which is ultimately not helpful.

For one thing function is one kind of expression ie its a subset not a disjoint relation.

More important (in this case) its bad pedagogy.
Its generally accepted that side-effecting functions are not a good idea
-- typically a function that returns something and changes global state.

In that sense its best to think of print(x) as syntactically an expression, 
semantically a statement.

Or put differently, the following error is more poorly reported in
python3 than in python2

Python 2.7.8 (default, Oct  7 2014, 17:59:21) 
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + (print 2)
  File "<stdin>", line 1
    2 + (print 2)
             ^
SyntaxError: invalid syntax


Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + (print (2))
2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

=========
tl;dr I dont think all this is very helpful to Seymore



More information about the Python-list mailing list