[Python-ideas] Simplifying .format() based string interpolation

Terry Reedy tjreedy at udel.edu
Fri Feb 7 11:17:23 CET 2014


On 2/7/2014 2:28 AM, spir wrote:
> On 02/07/2014 02:46 AM, Chris Angelico wrote:

>> (Note that tuples do kinda have a literal syntax.

'Constant tuples are no different that other constant expressions for 
immutable objects. Like tuples, ints are immutable. If the fixed value 
of an int can be computed at compile time, then an implementation may 
opt to optimize runtime by doing the computation at compile time. This 
only really helps if it avoids computing the object multiple times. I 
suppose one could say that '1 + 1' is a kind of literal syntax for 2, 
but I am not sure this is helpful in this context.

Number and string literals are *lexical* constants, as are keywords. 
They are all described in the chapter on *lexical* analysis of code. 
Literals are like the base cases of recursion and starting values of 
iteration. If you try to treat literals as Python runtime expressions, 
say 1 = int(1), then you get into infinite regression, as then int(1) = 
int(int(1)), etcetera.

> Well, in fact all your argumentation just supports the proposal, doesn't
> it?

If the argumentation led you to confuse categories, it is defective.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list