【发布时间】:2019-09-13 04:27:21
【问题描述】:
我不明白为什么它不起作用,但我是编程新手,所以我可能会犯一些简单的错误。
def tuplasemstr(t):
tup1 = []
n = 0
while n <= 2 and type(t[n],) != str:
list.append(tup1, t[n])
n = n + 1
return tuple(tup1)
我期待的是这样的:
t = ("a",3,2.1)
输出:
(3,2.1)
【问题讨论】:
-
顺便说一句,你真的不应该在这里使用while循环。请注意,
while n <= 2 and type(t[n],) != str:将在您第一次遇到字符串时终止。
标签: python python-3.x list while-loop tuples