3

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

0

1 Answer 1

5

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'
Sign up to request clarification or add additional context in comments.

1 Comment

what if its like "I love 10 coding"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.