prasoonthegreat at gmail.com
Tue Jun 16 13:36:07 CEST 2009
On Jun 16, 3:34 pm, Francesco Bochicchio <bieff... at gmail.com> wrote:
> On 16 Giu, 11:32, Prasoon <prasoonthegr... at gmail.com> wrote:> I am new to python....and using python 2.6
> > I want to know when to use raw_input( ) and when to use input( )???
> > According to my interpretation one should use input( ) when entering
> > numbers etc and
> > raw_input( ) when a string is too be entered.....
> > Correct me if I am wrong....
> You should almost always use raw_input and write your own code to
> validate the
> input and convert it. input (wich is roughly equivalent of veval
> is officially considered a Bad Choice and as such has been changed in
> Python 3.x
> ( that is, python 3.x 'input' is equivalent to python 2.x raw_input ).
> P.S : if you are new to python and don't expect to use external
> libraries for the next
> months (one year?) you might consider to start directly with python
> > Also if I want to enter two numbers 'a' and b such that while entering
> > them through the keyboard
> > there is a space between the two...
> > For example:>>>Enter two numbers:
> > .....12 15
> > Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'????
> > I mean how to handle spaces???/
> For instance: map( int, raw_input.split() ) splits the
> input string using blanks as separator, then try to convert each piece
> in an integer
> and returns a list of integer. Of course if the input string is not a
> list of integer
> you get an exception.
> You could also do:
> a, b = map( int, raw_input.split() )
> but in this case you get an exception also if the input strings
> cobntains less or more than two integers.
I think you meant
a, b = map( int, raw_input().split() )
More information about the Python-list