New user's initial thoughts / criticisms of Python
jpiitula at ling.helsinki.fi
Sat Nov 9 15:24:41 CET 2013
John von Horn writes:
> Hi Everyone,
> I'm Mr. Noobie here, I've just started easing into Python (2.7.4)
> and am enjoying working along to some youtube tutorials. I've done a
> little programming in the past.
> I've just got a few thoughts I'd like to share and ask about:
> * Why not allow floater=float(int1/int2) - rather than floater=float
> Give me a float (or an error message) from evaluating everything in
> the brackets. Don't make me explicitly convert everything myself
> (unless I want to)
The guardians of the language agree with you and have changed this in
Python 3. You can import the change to 2.7 thus:
>>> from __future__ import division
> * No sign of a select .. case statement
I won't comment on that.
> * Call me pedantic by why do we need a trailing comma for a list of
> one item? Keep it intuitive and allow lstShopping= or ["Bread"] or
> ["Bread", "Milk","Hot Chocolate"] I don't like ["Bread",]. It bugs
Just write ["Bread"]. The comma is not needed.
Round brackets are used mainly for grouping expressions and calling
functions. Commas are used to separate function arguments and elements
of collections like lists, dictionaries, and sets, and to construct
tuples. The awkward case you have in mind is a one-element tuple that
has to be written with a trailing comma.
Best get used to that. It's just the optional trailing comma, but one
doesn't want just 3 or (3) interpreted as a tuple - not in Python
anyway - so in the one-element case optional becomes mandatory.
More information about the Python-list