有没有办法在Python中将输出与输入函数分开?
例如,假设我们要插入数字和姓名。
input('Give number and name:')
Give number and name:14,John
'14,John'
我们得到'14,John'
。有办法服用'14','John'
吗?
谢谢。
答案 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'