There is no direct equivalent to scanf in Python, but this should work
somearray = map(int, raw_input().split())
In Python3, raw_input been renamed to input
somearray = map(int, input().split())
Here is a breakdown / explanation
>>> raw=raw_input() # raw_input waits for some input 1 2 3 4 5 # I entered this >>> print raw 1 2 3 4 5 >>> print raw.split() # Make a list by splitting raw at whitespace ['1', '2', '3', '4', '5'] >>> print map(int, raw.split()) # map calls each int() for each item in the list [1, 2, 3, 4, 5]
source share