In C, enter multiple value is very convenient, because in the C language has a special convenient data types, called an array, the array can be defined ahead of its size, multiple values in an array input, we can input, with space, can be in the line of the multiple values of the input to the array, but in py language, not an array of the structure, but it can also be a line of input multiple values, such as (assuming three values for input can say like this: a, b, C=map (int, input (). The split ())), the operation implements in a row to ABC the three variables of the value of the input, just can be separated by a space, can input, but if you want to 10 or 20 or 100 line of the input value, you can't go to 20 or 100 variables in map method to input, this is very time consuming, and low efficiency, waste of resources, this time we will think of how to use C language array types to py analogy in the language of the list type, the multiple input variables are separated by a line of multiple values, we can construct a function, so don't say, code,
# def hao: (a) a is type int, analogy in c language array of int arr [a]
List0=[] # define an empty list
For I in range (a) :
List0. Append (0) # will have a full list to zero element
Length is similar to the length of the array in C
Str0=input () # input a elements separated by a space, we can get a line of string
List1=str0. Split (') # will split line above the string with a space, become a list of elements, the elements in the list at this time or string type,
For I in range (a) :
List0 [I]=int (list1 [I]) # will list elements like string is converted to an integer, and gives corresponding element value to the front of the list,
Return list0
Finally, we will return to, the list of the list is as a result, we get the list there is a value
CodePudding user response:
Str1=input (" input a set of Numbers ")
Liststr=str1. Split (" ")
Print (liststr)
CodePudding user response:
To learn PYTHON, process control can refer to the thinking of the C language, but implementation cannot copy!