On Fri, May 14, 2021 at 07:05:43PM -0000, Martin Teichmann wrote:
> Hi Paul,
> 
> > Also consider the section in the PEP format "How would we teach this?"
> > How would you explain to someone with no programming background, maybe
> > a high school student, that 3/4 and 3 / 4 mean different things in
> > Python? Your audience might not even know that there is a difference
> > between "fraction", "decimal" and "float" at this stage.
> 
> Well, I think a high school student would be the one with the least 
> problems: s/he would just realize "wow, that thing can do fractions! I 
> can do my math homework with that!" And I can tell you, kids will be 
> the first ones to figure out that if you type spaces you get decimals, 
> if you do not type spaces you get fractions. They are used to this 
> kind of stuff from their math class, from calculators (or their 
> phones, I guess).

*raises hand*

Not any students I work with.

No text book I've seen teaches that `1 / 2` and `1/2` are different 
things (one a rational fraction and the other a decimal). And no 
calculator I've seen, and I've seen a lot (I'm a bit of a calculator 
geek...) treats them differently. Most scientific calculators don't even 
have a way of entering spaces.

Both the Texas Instruments "Nspire" and Casio "Classpad" have a global 
setting that controls whether calculations between integers result in 
exact fractional, or symbolic, values, or a potentially inexact decimal 
approximation. The Nspire also allows the user to force a decimal by 
using a decimal point in any of the input values. Spaces make no 
difference in either.

In Python it would be odd to have space sensitivity for operators. For 
every operator ⊕, the presence or absence of surrounding spaces makes no 
difference, provided the operator can be unambiguously parsed:

    >>> []or{}
    {}

And it applies to the dot pseudo-operator, with the same restriction:

    >>> str . find
    <method 'find' of 'str' objects>

There's really only one common case where spaces make a difference: 
float literals cannot contain spaces, so `1 .` is interpreted as the 
dot pseudo-operator applied to the int 1, rather than the float `1.`

But that's a consequence of the parsing rules, not a difference in the 
operator.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JTSGYHQVRLJRVHIBQBTPHBU6YXAMDBDF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to