Conditional operator in Python?
Joshua Marshall
jmarshal at mathworks.com
Wed Apr 4 15:39:00 EDT 2001
Steven D. Majewski <sdm7g at virginia.edu> wrote:
>>>> def Number( *args ):
> ... t = 0
> ... for x in args:
> ... t = t * 1000L
> ... assert 0 <= x < 1000, 'Out of range'
> ... t = t + x
> ... return t
> ...
>>>> Number( 1,000,000 )
> 1000000
>>>> Number( 1,234,567)
> 1234567
>>>> Number( 1,200,300,400,500 )
> 1200300400500L
>>>> Number( 1,200,300,400,500.25 )
> 1200300400500.25
> Of course, you can also have confusing things like:
>>>> Number( 1,2,3 )
> 1002003
Be careful with this--octal notation (numbers beginning with 0) will
break it.
More information about the Python-list
mailing list