Q: "...Learning with Python" ...a property that addition and multiplication have...

mensanator at aol.com mensanator at aol.com
Wed May 25 21:33:18 EDT 2005



jeffbernstein at yahoo.com wrote:
> Greetings.
>
> I'm reading "How to think like a computer scientist: Learning with
> Python" and there's a question regarding string operations. The
> question is, "Can you think of a property that addition and
> multiplication have that string concatenation and repetition do not?"
>
> I thought it was the commutative property but "<string>"*3 is
> equivalent to 3*"<string>". Any ideas?

>>> 3.3*1
3.2999999999999998

>>> 3.3*'1'

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in -toplevel-
    3.3*'1'
TypeError: can't multiply sequence to non-int

> 
> Thanks,
> 
> Jeff




More information about the Python-list mailing list