What is a function parameter =[] for?
Steven D'Aprano
steve at pearwood.info
Tue Nov 24 19:36:01 EST 2015
On Wed, 25 Nov 2015 08:25 am, Antoon Pardon wrote:
> The point is that a
> tuple can just be loaded as a constant without needing something extra.
How would one load this tuple as a constant?
(myfile.read(), "%.5f" % sin(x or y))
The point is that *in general*, tuple so-called "literals" (what the docs
call displays) cannot be loaded as constants. If, and only if, the tuple
contains nothing but immutable constants e.g.
(1, 2.0, None, "spam")
then a sufficiently smart compiler may be able to treat that specific tuple
as a constant/literal. But that's a special case, and cannot be generalised
to all tuple displays.
All tuple so-called "literals" e.g. (), (1, 2), (x, y, z) etc. are
fundamentally expressions that *may* have to be built at runtime. Hence the
word "literal" is inappropriate.
--
Steven
More information about the Python-list
mailing list