使用字符串和整数从输入中获取整数

时间:2021-07-04 23:15:37

标签: python python-3.x python-3.8

我想弄清楚当既有整数又有字符串时如何从输入中取出整数。

例如,如果我输入“hello 3”,有没有办法将“3”与“hello”之外的另一个变量分开?

1 个答案:

答案 0 :(得分:0)

这对你有用吗:

myInput=input() # Get Input
myString,myIntStr=myInput.split(" ") # Split in to list based on where the spaces are
myInt=int(myIntStr) # Convert to int