How to replace a comma

Jussi Salmela tiedon_jano at hotmail.com
Mon Dec 18 10:48:34 EST 2006


Lad kirjoitti:
> 
> Thank you for ALL for help.
> Hendrik,
> your solution works great but
> what is `_`  in
> _.replace(',',', ')
> 
> for?
When you are trying things out in the Python shell IDLE, _ is a 
shorthand way to use the last value printed by IDLE.

Thus when
	s.replace(', ',',')
prints out
	'hello,goodbye,boo'
_ refers to that value so the replace operation
	_.replace(',',', ')

manipulates that value.

Cheers
Jussi
> Thank you
> La.
> 
>> re's are a pain.  Do this instead:
>>
>>>>> s = "hello, goodbye,boo"
>>>>> s.replace(', ',',')
>> 'hello,goodbye,boo'
>>>>> _.replace(',',', ')
>> 'hello, goodbye, boo'
>> Hope this helps - Hendrik
> 



More information about the Python-list mailing list