简体   繁体   中英

separate output of input() function in Python [duplicate]

This question already has an answer here:

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.

Does this work?

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

number, name = user_input.split(", ")

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

Question not resolved ? You can try search: separate output of input() function in Python [duplicate].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2023 STACKOOM.COM