Knowledge Base‎ > ‎Programming‎ > ‎Python‎ > ‎Python Reference‎ > ‎

raw_input()


Related:

 Examples

 
 
username = raw_input("Please enter your username: ")

 Description        

 
A built in function that allows the user to input information using the keyboard.

Note: all input coming from raw_input is of type string. If you need to use numeric input from the user as some other type you will need to convert it first - see interpreter session below.

 Syntax

 
 
variable = raw_input(prompt)

 Parameters

 
variable - a legal variable name in which to store the input from the user

prompt - the message to give the user when asking for input

 Interpreter

 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 

[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> username = raw_input("what is your username? ")

what is your username? Bart

>>> username

'Bart'

>>> type(username)

<type 'str'>

>>> age = raw_input("what is your age? ")

what is your age? 15

>>> age

'15'

>>> type(age)

<type 'str'>

>>> age = int(age)

>>> age

15

>>> type(age)

<type 'int'>




Comments