Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
n 这里得到一个句子的输入,比如“嗨,我是初学者”
n=list(map(str,input().split()))
input().split()
我需要将其转换为字符串列表都可以,但是...
有什么区别?
这里不需要 list(map()) 吗?
input()总是返回一个字符串。
input()
所以map(str,input().split())是多余的,等价于input().split()
map(str,input().split())
参考:输入()
这两种方式是等价的,你只需要写第二种方式。但是如果你需要一个 int 类型或其他类型的列表,你可以这样写:
n = list(map(int, input().split()))