Parentheses (as after "print")

Stefan Behnel stefan_ml at behnel.de
Tue Sep 26 15:19:04 EDT 2017


Stefan Ram schrieb am 26.09.2017 um 17:56:
>   Why do we newbies write »print 2«? Here's another hint.
>   This is an original transcript of what happened to me today:
> 
> |>>> import( operator )
> |  File "<stdin>", line 1
> |    import( operator )
> |          ^
> |SyntaxError: invalid syntax
> |
> |>>> import operator
> |
> |>>> help operator
> |  File "<stdin>", line 1
> |    help operator
> |                ^
> |SyntaxError: invalid syntax
> |
> |>>> help( operator )
> |Help on module operator:
> 
>   What happened? I woke up today in parens mood. So I typed:
> 
> import( operator )
> 
>   Python told me that I should type:
> 
> import operator
> 
>   . Fine, Python conditioned me to omit the parens. 
>   So now I was in noparens mood. So I typed:
> 
> help operator
> 
>   . Oops!

But would you also write this?

    for(i in [1,2,3]): ...

    def(func(a,b,c)):
        return(a+b+c)


>   "Don't make me think!"

In language design, some things are worth being keywords, while others are
not. Having less keywords is generally a good thing, but for some
functionality, the parser/compiler needs to be able to safely detect and
process it, so some things really need to be keywords.

An import is an assignment, for example. It stores a reference to the
module (or its attributes) in variables. A function call cannot do an
assignment. The same applies to function definitions and loops. They all do
assignments, or even change the program execution flow.

print() and help() are definitely not worth being keywords. They do not
impact the program flow, they don't do any assignments, nothing. That's why
they are simple functions.

Stefan




More information about the Python-list mailing list