This article mainly introduces the differences between input () and raw_input () in python. For more information, see the source code of input.
Def input (prompt ):
Return eval (raw_input (prompt ))
Actually, the input also calls raw_input, but implements eval processing.
What is the role of eval?
Input: converts data types based on user input.
Raw_input: the user input is processed as a string.
Below is a detailed supplement:
First, we know that both input () and raw_input () are used to obtain the input from the console. of course, the input prompt information can be added during input:
a = raw_input("Please input a:") b = input("Please input b:")
So what is the difference between the two?
Input () allows you to enter numbers or expressions. input strings are not supported and numeric values are returned. Raw_input () captures the original input, that is, a string is returned. Therefore, if the input is a number, we must perform a forced conversion. For example:
a = int(raw_input("Please input the number a:"))
In fact, input () is implemented by raw_input () in essence. it only calls the eval () function after raw_input () is called. Therefore, unless there is a special need for input, otherwise, we recommend that you use raw_input () to interact with users.
Map receives a function and an iteratable object (such as a list) as a parameter, processes each element with the function, and then returns a new list.
ACM sometimes needs to input a row in the format of a B c, and then it uses the map function for processing. Here we assume that a, B, and c are integers.
A, B, c = map (int, raw_input (). split (). The raw_input function inputs a string. the string split method is used to divide the string into sequences.
For more information about the differences between input () and raw_input () in python, see PHP!