Differences between input and raw_input in Python

Source: Internet
Author: User
This article mainly introduces the differences between input and raw_input in Python. they are all used to read the input functions in the console. if you need them, you can refer to using both input and raw_input to read the input in the console, however, there is a difference between input and raw_input when processing numbers.

When the input is a pure number:

Input returns numeric values, such as int and float.
Raw_inpout returns the string type and the string type.

Input string as expression

Input calculates the number expression in the string, but raw_input does not.

For example, enter "57 + 3 ":

Input returns an integer of 60.

Raw_input will get the string "57 + 3"

Python input implementation

Read the python input document and you can see that the input is actually implemented through raw_input. The principle is very simple. the following code line is as follows:

The code is as follows:


Def input (prompt ):
Return (eval (raw_input (prompt )))

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.