The difference between the input of Python and raw_input

Source: Internet
Author: User

Input () and raw_input () are all actually for the user to enter data, when the integer or floating-point number is recorded is not very different, because the user directly input raw data can be saved directly into the variable, for example:

>>> i = input (' I: ') i:123>>> print i123


However, when the user entered a string is a little trouble, we can not ask the user to enter the string to add (' "), so that is not the user experience is too bad? For example:

>>> s = input (' s: ') s: ' abc ' >>> print sabc>>>>>> s = input (' s: ') S:abctraceback (most Recent call last): File ' <stdin> ', line 1, in <module> file ' <string> ', line 1, in <module>namee Rror:name ' abc ' is not defined>>>


At this point, we need to consider the use of the Raw_input () function, the function is to put the input data as raw data, and then put in the string to save, we look at the effect:

>>> s = raw_input (' s: ') s:abc>>> print SABC


This article is from the "small white Plus small white" blog, please be sure to keep this source http://bxtser.blog.51cto.com/9259025/1671289

The difference between the input of Python and raw_input

Related Article

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.