4

How to get both int and string inputs from one input line in python Example: For the given line

10 I love coding

i want to get the 10 and I love coding as separate variables. I tried input().split() but as there is space between I and love there arises a confusion

Divakar Rajesh
  • 1,140
  • 2
  • 18
  • 23

1 Answers1

6

You can limit the split:

>>> input().split(maxsplit=1)
10 I love coding
['10', 'I love coding']

>>> a,b = input().split(maxsplit=1)
10 I love coding
>>> a
'10'
>>> b
'I love coding'
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251