Reading Space separated input in python
the_string = input()
name, age = the_string.split()
In Python 2, use raw_input
instead of input
.
If you have it in a string, you can use .split()
to separate them.
>>> for string in ('Mike 18', 'Kevin 35', 'Angel 56'):
... l = string.split()
... print repr(l[0]), repr(int(l[1]))
...
'Mike' 18
'Kevin' 35
'Angel' 56
>>>