Python data input
I recently started learning Python and I ran into one problem. Suppose you are given integers separated by a space, say 4 5 6
When I use the input () method and take input, it shows me an error.
Traceback (most recent call last):
File "P_Try.py", line 1, in <module>
x= input();
File "<string>", line 1
4 5 6
^
SyntaxError: invalid syntax
I think since it is on the same line it assumes it is a string, but it detects an integer at location 2 (index starting at 0). I tried an alternative method that I took as a string using the raw_input () method, and wherever I find a number, I passed it as an int and added it to the list.
Is there a better way to accomplish the task?
+3
source to share
4 answers