[Tutor] input with default value option
Alan Gauld
alan.gauld at freenet.co.uk
Tue Apr 11 13:27:17 CEST 2006
>> With raw_input(), it allows to input value. Can it be used to input value
>> with default value option?
>>
> response = raw_input("Enter some data:")
> if not response: response = "default value"
This is one of the few places where I do use the short-circuit evaluation
trick:
val = raw_input('> ') or myDefault
I reads well (IMHO) and works pretty much safely.
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list