Formatted Input

Discussion in 'Python' started by Deep, Mar 10, 2007.

  1. Deep

    Deep Guest

    Hi all,
    I am a newbie to python
    I have an input of form
    <one number> space <another number>
    ie.
    4 3
    how can i assign these numbers to my variables??
     
    Deep, Mar 10, 2007
    #1
    1. Advertising

  2. Deep

    Dan Bishop Guest

    On Mar 10, 1:29 pm, "Deep" <> wrote:
    > Hi all,
    > I am a newbie to python
    > I have an input of form
    > <one number> space <another number>
    > ie.
    > 4 3
    > how can i assign these numbers to my variables??


    n1, n2 = map(int, raw_input().split())
     
    Dan Bishop, Mar 10, 2007
    #2
    1. Advertising

  3. Deep

    Larry Bates Guest

    Deep wrote:
    > Hi all,
    > I am a newbie to python
    > I have an input of form
    > <one number> space <another number>
    > ie.
    > 4 3
    > how can i assign these numbers to my variables??
    >


    Or with list comprehension:

    n1, n2 = [int(n) for n in raw_input().split()]

    Neither of these methods checks for errors (e.g. non-integers)

    -Larry
     
    Larry Bates, Mar 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    455
    Eric Reitmaier
    Oct 19, 2004
  2. TheDD
    Replies:
    4
    Views:
    532
    John Harrison
    May 13, 2004
  3. TheDD
    Replies:
    7
    Views:
    402
    TheDD
    May 15, 2004
  4. dkk

    formatted input/output question

    dkk, Apr 10, 2006, in forum: C Programming
    Replies:
    2
    Views:
    335
    Herbert Rosenau
    Apr 12, 2006
  5. Jason Heyes
    Replies:
    0
    Views:
    279
    Jason Heyes
    Jun 24, 2005
Loading...

Share This Page