New user's initial thoughts / criticisms of Python

Ned Batchelder ned at nedbatchelder.com
Sat Nov 9 14:22:59 CET 2013


On Saturday, November 9, 2013 8:08:25 AM UTC-5, John von Horn wrote:
> 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
> (int1)/float(int2)?
> 
> 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 language has to specify what int1/int2 should evaluate to.  Python 2 says it is an int.  Once that computation is done, passing that int to float() can't bring back the lost information.  Python 3 says that int1/int2 produces a float, and you can get that behavior if you use "from __future__ import division" at the top of your Python 2.7 file.

> * No sign of a select .. case statement
> 
> Another useful tool in the programmer's toolbox
> 
> Select DayofWeek
> 
> 	case "mon"
> 
> 	...
> 
> end select
> 

This is a bit more controversial.  Python has no select statement because it has very little advantage over simply using an if/elif/elif/else ladder. In languages like C, a switch compiles to a table lookup.  In Python, all the actual comparisons would have to be done anyway, so it would simply be an alternate syntax for a number of if statements.  In the interest of not cluttering the language, the switch statement doesn't exist.

> * 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 me.
>

You're mistaken: One-element lists are written without a trailing comma, though you are allowed to include them.  One-element tuples, though, require the trailing comma, since ("hello") is just the same as "hello".

Welcome to Python!
 
> JvH




More information about the Python-list mailing list