From D

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Wed Jul 25 22:04:01 EDT 2007


On Wed, 25 Jul 2007 18:17:19 -0700, mensanator at aol.com wrote:

> On Jul 25, 8:00 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> wrote:
>> "mensana... at aol.com" <mensana... at aol.com> writes:
>> > On Jul 24, 6:08 pm, Steven D'Aprano
>> > <st... at REMOVE.THIS.cybersource.com.au> wrote:
>> > > Python already does:
>> > > "hello-" "world" => "hello-world"
>>
>> > > Propose:
>> > > 123 456 789 => 123456789
>> > > 123.456 789 => 123.456789
>>
>> > So, spaces will no longer be delimiters?
>>
>> I don't see how you get that conclusion from Steven's proposal.
> 
> IDLE 1.2c1
>>>> s = '123 456'
>>>> s.split()
> ['123', '456']
> 
> The only way to get '123 456' would be to treat a space as a
> non-delimiter. But what if those actually WERE two different numbers?

That makes no sense at all. Your example is about splitting a _string_.
You can construct and split the string any way you like:

>>> s = '123SURPRISE456'
>>> s.split('SURPRISE')
['123', '456']

Notice that the results aren't ints, they are strings.

To get an int literal, you currently type something like 123456. 123 456
is currently not valid in Python, it raises an SyntaxError. Try it for
yourself:

>>> 123 456
  File "<stdin>", line 1
    123 456
          ^
SyntaxError: invalid syntax

If you want two numbers, you would do exactly the same thing you would now:

>>> x, y = 123, 456
>>> print "x is %d and y is %d" % (x, y)
x is 123 and y is 456



-- 
Steven.




More information about the Python-list mailing list