0

Is there a way to separate the output from the input function in Python?

For example, let's say that we want to insert a number and name.

input('Give number and name:')
Give number and name:14,John
'14,John'

We get '14,John'. Is there a way to take '14','John'?

Thanks in advance.

Joel
  • 1,564
  • 7
  • 12
  • 20
G1I2A
  • 3
  • 1
  • 4

2 Answers2

0

Does this work?

user_input = input("Please write a number then a name, separated by a comma: ")

number, name = user_input.split(", ")
Aviv Shai
  • 997
  • 1
  • 8
  • 20
0

Use .split()

>>> input('Give number and name: ').split(',')
Give number and name: 14,John
['14','John']

or

>>> number, name = input('Give number and name: ').split(',')
Give number and name: 14,John
>>> number
'14'
>>> name
'John'

Note that they are both strings

Alex
  • 6,610
  • 3
  • 20
  • 38