A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/090737.html below:

Conditional operator in Python?

Conditional operator in Python?Tim Peters tim.one at home.com
Wed Apr 4 15:05:34 EDT 2001
[Steven D. Majewski]
> Obviously a performance hit, but if you want readability:
>
> >>> 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

That's not confusing.  This is <wink>:

>>> Number(1,064)
1052L
>>>

hard-to-believe-that-semantically-significant-leading-zeroes-
    ever-seemed-like-"a-good-idea"-to-anyone-ly y'rs  - tim



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4