Python如何同时输入整数和字符串

Python如何同时输入整数和字符串并用空格隔开

a,b=input().split(' ')
a = int(a)

print(a,type(a))
print(b,type(b))

img

如有帮助,望采纳!谢谢!

使用输入函数input,字符串分割函数split及转整函数int操作,这样即可:

a=input().split(' ')
n,s=int(a[0]),a[1]
print(n,s)
print(type(n),type(s))

运行结果:

F:\2021\qa\ot2>t5
3 abc
3 abc
<class 'int'> <class 'str'>

如对你有帮助,请采纳。点击我回答右上角【采纳】按钮。