【发布时间】:2021-05-03 01:11:22
【问题描述】:
L = [1,2,3]
q = " ".join(str(x) for x in L)
print(q)
# as you see input is = L = [1,2,3]
# when you run the code output = 1 2 3
但是当我想像这样使用这段代码时:
L = input("Enter your lst: ")
q = " ".join(str(x) for x in L)
print(q)
# I enter my input again = [1,2,3]
# and the output is = [ 1 , 2 , 3 ]
# but I was looking for this : 1 2 3
这里有什么问题?我应该怎么做才能获得 True 输出并将输入列表转换为字符串?
我对编码很熟悉,所以简单的解释会更好。
【问题讨论】:
-
在
L = input("Enter your lst: "),L已经是一个字符串 -
@python_user 当然是的
-
只输入不带括号的数字。逗号和空格以获得所需的输出
-
问问自己(并阅读官方文档!),
input语句返回什么?提示:docs.python.org/3/library/functions.html#input -
@IronFist 我只想知道为什么会这样!
标签: python string list converters