-4

Like C

int a,b,c; 
scanf("%d %d %d",&a,&b,&c);

how can I take multiple variable in python 3.4

Blackcoat77
  • 1,574
  • 1
  • 21
  • 31
  • `while loop`, `for loop`, ask for some spliting character and just split your input into different variables. So many ways of doing it. – MooingRawr Jan 26 '17 at 15:39
  • Sorry sir but I want without looping. Like >>> a,b = input().split() // but this is not working – Rayhan Mahmud Jan 26 '17 at 15:44

2 Answers2

2

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
>>> 
Christian Dean
  • 22,138
  • 7
  • 54
  • 87
0

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]

bobtt
  • 73
  • 8