Multiplying sequences with floats
cito at online.de
Fri Mar 24 00:35:44 CET 2006
Currently, if you write 3*'*', you will get '***', but if you write
3.0*'*', you will get an error (can't multiply sequence by non-int).
I was wondering whether this should be allowed, i.e. multiplication of a
sequence with a float. There could be either an implicit typecast to int
(i.e. rounding), or the above error could occur only for floats with a
fractional part. Usage example: You want to convert a percentage value
(to a number of 0 to 4 stars. You could do this with the expression
However, this fails if percentage is a float. And even this fails:
So you have to write
in which case you may as well write
again. Ok, it's probably not a big deal but it somehow stroke me as odd
that you can't simply write percentage//20*'*'.
More information about the Python-list