Like C
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
how can I take multiple variable in python 3.4
Like C
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
how can I take multiple variable in python 3.4
Python does not have an equivalent to C's scanf()
. Instead, you must parser the user input you receive into variables yourself.
Python provides several tools for accomplishing this. In your case, one method would be to require the user to enter n, whitespace separated strings. From there, you can then split the string into a list, convert each element to an integer, and unpack the list into n variables.
Here is a short demo using three integers:
>>> # For the sake of clarity, I do not include
>>> # any error handling in this code.
>>>
>>> ints = input()
12 34 57
>>> a, b, c = [int(n) for n in ints.split()]
>>> a
12
>>> b
34
>>> c
57
>>>
if you just have number you can use a regex
lets supose your input is "12,13,47,89,14"
input = "12 13 47 89 14"
parsed_args = map(int, re.findall("\d+",input))
ouput
[12, 13, 47, 89, 14]