The difference between Python input and the Raw_input function

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/sruru/article/details/7790436

Previously did not deeply consider the difference between the raw_input and the input function, so has been more confused, today after testing, have a more in-depth understanding, recorded as follows

>>> user = Raw_input ("Enter your name:") Enter your NAME:SCR>>>User'SCR'>>> user = Raw_input ("Enter your name:") Enter your name:123>>>User'123'>>> user = input ("Enter your name,please!") Enter your name,please!4>>>User4>>> user = input ("Enter your name,please!") Enter your name,please!"SCR">>>User'SCR'>>> user = input ("Enter your name,please!") Enter your name,please!Scrtraceback (most recent): File"<pyshell#67>", line1,inch<module>User= Input ("Enter your name,please!") File"<string>", line1,inch<module>Nameerror:name'SCR'  isNot defined>>>

Summarize:

Raw_input more in line with user input habits, the conversion of any user input into a string storage, in the need of other types of data, call the corresponding function to convert;
Input user inputs What to store what, so the user input must conform to the Python syntax requirements, otherwise there will be an error, such as

>>> user = input ("Enter your name,please!") Enter your name,please!Scrtraceback (most recent): File"<pyshell#67>", line1,inch<module>User= Input ("Enter your name,please!") File"<string>", line1,inch<module>Nameerror:name'SCR'  isNot defined>>>

The difference between Python input and the Raw_input function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.