Input and raw_input can be used to read the console inputs, but input and raw_input are different when working with numbers
Pure Digital input
When the input is a pure number
Input returns a numeric type, such as Int,float
Raw_inpout return String type, String type
Input string is an expression
Input computes the numeric expression in the string, and Raw_input does not.
If you enter "57 + 3":
Input will get an integer 60
Raw_input will get the string "57 + 3"
Implementation of Python input
Look at the Python input document, you can see that input is actually implemented through raw_input, the principle is very simple, the following line of code:
def input (prompt):
Return (eval (raw_input (prompt)))
Python raw_input Read Input value
The following describes the use of Python raw_input,
The raw_input can be used to read data in a very convenient bundle console.
1. Input string
#13222319810101 * * *
NID = "
While 1:
NID = raw_input ("Input your id plz")
If Len (nID)! = Len ("13222319810101****"):
print ' wring length of id,input again '
Else
Break
print ' Your ID is%s '% (NID)
2. Enter an integer
nAge = Int (raw_input ("Input your Age plz:\n")
If NAge > 0 and NAge < 120:
print ' thanks! '
Else
print ' bad age '
print ' Your age is%d\n '% nAge
3. Enter floating-point type
Fweight = 0.0
Fweight = float (raw_input ("Input your weight\n"))
print ' Your weight is%f '% fweight
4. Enter 16 binary data
Nhex = Int (raw_input (' Input hex value (like 0x20): \ n '), 16)
print ' Nhex =%x,noct =%d\n '% (Nhex,nhex)
5. Enter 8 binary data
noct = Int (raw_input (' Input Oct value (like 020): \ n '), 8)
print ' noct =%o,ndec =%d\n '% (noct,noct)
Reprint: http://blog.csdn.net/kjing/article/details/7450146
Python:raw_input and input usage