[Tutor] reading inputs from keyboard

bob gailer bgailer at gmail.com
Sun Dec 14 15:00:26 CET 2008


Ajo Augustine wrote:
> hi all;
> can u let me know how  to  read an input string  from the keyboard?

In Python 2.6 and lower:

raw_input(prompt)

Example program:

name = raw_input("Enter your name:")
print "Hello", name
raw_input("Press any key to exit.")

In Python 3

Example program:

name = input("Enter your name:")
print ("Hello", name)
input("Press any key to exit.")

The purpose of the last line - when you run the program by 
double-clicking or equivalent this keeps the window open so you can see 
the results.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239



More information about the Tutor mailing list