小编cap*_*ion的帖子

为什么我在Python中使用int(input().strip())而不是int(input())?

如果我想取一个数字作为输入,我还需要这个.strip()方法吗?像这样:

n = int(input().strip())
Run Code Online (Sandbox Code Playgroud)

而不仅仅是编码:

n = int(input())
Run Code Online (Sandbox Code Playgroud)

我知道.strip()返回一个字符串的副本,其中所有字符都已从字符串的开头和结尾剥离.但我想知道为什么/如果有必要.

python string int

7
推荐指数
1
解决办法
1550
查看次数

标签 统计

int ×1

python ×1

string ×1