Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Formatted Input

Reply
Thread Tools

Formatted Input

 
 
Deep
Guest
Posts: n/a
 
      03-10-2007
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??

 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      03-10-2007
On Mar 10, 1:29 pm, "Deep" <(E-Mail Removed)> 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())

 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      03-12-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formatted input/output question dkk C Programming 2 04-12-2006 05:27 PM
Reporting formatted input operations that fail Jason Heyes C++ 0 06-24-2005 06:19 AM
J2SE 1.5 Formatted Input Question Matt Java 3 10-19-2004 08:07 AM
Formatted input interpretation TheDD C++ 7 05-15-2004 10:19 PM
From unformatted to formatted input TheDD C++ 4 05-13-2004 09:51 AM



Advertisments