Python中input()函数的单独输出

时间:2018-11-14 16:54:58

标签: python python-3.x

有没有办法在Python中将输出与输入函数分开?

例如,假设我们要插入数字和姓名。

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

我们得到'14,John'。有办法服用'14','John'吗?

谢谢。

2 个答案:

答案 0 :(得分:0)

这行吗?

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

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

答案 1 :(得分:0)

使用MyDialogFragment dialog = new MyDialogFragment(); dialog.setListener(this); dialog.setCallingActivity(this); FragmentManager fm = getSupportFragmentManager(); dialog.show(fm, "MyDialogFragment");

.split()

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

请注意,它们都是>>> number, name = input('Give number and name: ').split(',') Give number and name: 14,John >>> number '14' >>> name 'John'