How python uses the raw_input () function
This article mainly introduces how python uses the raw_input () function, which is very detailed and has a certain reference value. Friends who are interested must finish it!
Raw_input () function
Raw_input (): reads the input statement and returns the string string, ending with a newline character.
> name = raw_input ("please input your name:") please input your name:abc > print (name) abc > type (name)
Note: the difference between the input () and raw_input () function: (1) input supports the legal python table format "abc", and the string must be expanded in quotation marks; otherwise, it will report syntax errors (2) raw_input () returns all inputs as strings and returns string, while input () inputs numbers with its own characteristics, returning the input number type int or float.
# 1. Syntax error > name = input ("input your name:") input your name:abcTraceback (most recent call last:) File ", line 1, in File", line 1 In NameError: name 'abc' is not defined#2, correct input > name = input ("input your name:") input your name: "abc" > print (name) abc#3, input () data type > age = input ("your age:") your age:20 > type (age) # 4, Raw_input () data types are all str > age = raw_input ("your age:") your age:20 > type (age). These are all the contents of the article "how python uses the raw_input () function". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!