"...Learning with Python" ...a property that addition andmultiplication have...

GMane Python s_david_rose at hotmail.com
Thu May 26 15:30:38 EDT 2005


The inablility to work with negative values.

Addition can do the following:
5 + (-4)  read as 5 plus the value negative four.

Multiplication can do the following:
5 * (-1) read as 5 times the value negative one.

String concatination can not subtract the sub-string 'lo' from 'hello'.
'hello' - 'lo' is invalid.

string repetition can not repeat a value negative times:
'hello' * -3 is invalid.
'hello' * 2.75 is also invalid, in that you can not repeat a fractional
amount.

-Dave
(Python Newbie)
<jeffbernstein at yahoo.com> wrote in message
news:1117067025.233387.323910 at z14g2000cwz.googlegroups.com...
> 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?
>
> Thanks,
>
> Jeff
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>






More information about the Python-list mailing list