New user's initial thoughts / criticisms of Python

Chris Angelico rosuav at
Sun Nov 10 10:22:56 CET 2013

On Sun, Nov 10, 2013 at 7:47 PM, Jorgen Grahn <grahn+nntp at> wrote:
> On Sat, 2013-11-09, Chris Angelico wrote:
>> On Sun, Nov 10, 2013 at 12:08 AM, John von Horn <j.h69 at> wrote:
> ...
>>> * 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)
>> As others have said, what you're asking for is actually magic. One of
>> the rules of Python - one for which I'm not aware of any exceptions -
>> is that you can always take a subexpression out and give it a new
>> name:
> And it's not just Python: programming languages have been designed
> that way since at least the 1960s.  People are used to analysing
> expressions inside and out according to rules common for almost all
> languages.

That's true to at least some extent, but quite a few languages have
differences here and there. In C, there's no such thing as an array
literal, only an initializer list, so:

/* This works: */
int month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int this_month_days = month_days[this_month];

/* This doesn't: */
int three = {1, 2, 3, 4, 5}[2];

PHP had similar issues up until a *very* recent version (5.3 or 5.4 or
something), where you couldn't dereference an array returned by a

$arr = func();
$val = $arr[5];

//Didn't work until recently, and therefore can't be trusted for
//deployment to random systems across the internet:
$val = func()[5];

JavaScript has magic around the dot and function-call operators, as I
mentioned earlier. Lots of other languages have some little quirk
somewhere that breaks this rule; some have a LOT of quirks that break
this rule. Does Python have any? Aside from parsing oddities like
attribute access on a literal integer[1], are there any cases where
two expressions yielding the same object are in any way different?

[1] You can write "(1234).to_bytes(2,'big')" but omitting the parens
gives a SyntaxError because it looks like the start of a float

More information about the Python-list mailing list