python输入整数_如何在Python中的一行中输入2个整数?
时间: 2023-07-16 11:15:23 浏览: 68
你可以使用 `input()` 函数来从控制台读取用户输入。如果要在一行中读取两个整数,可以使用 `split()` 函数将输入字符串分割成一个整数列表,然后使用 `map()` 函数将列表中的字符串转换为整数。例如:
```
a, b = map(int, input().split())
```
在上面的示例中,`input()` 函数将输入字符串读取到内存中,然后使用 `split()` 函数将其拆分成一个字符串列表。`map()` 函数将该列表中的每个字符串转换为整数,并将结果存储在变量 `a` 和 `b` 中。注意,这个方法假设用户输入的是两个用空格分隔的整数,例如 "3 4"。如果输入与此不同,则需要进行适当的修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)