范围功能不是迭代整个列表,请帮助我
def count4(lst):
count = 0
for i in range(lst[0],lst[-1]+1):
print(i)
print(count4([1,2,3,4,5,6,4,5,4,4]))
在这里,输出仅显示“ 1234”,而不是整个列表请告诉我如何使用范围函数迭代此列表。
def count4(lst):
count = 0
for i in range(lst[0],lst[-1]+1):
print(i)
print(count4([1,2,3,4,5,6,4,5,4,4]))
Here the output is showing just "1234" and not the whole list pls tell me how to iterate this list using range function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您作为“ 1234”输出的原因
将以下语句
解释为
即
解决:使用此信息
The reason you are getting output as "1234"
The below statement
is interpreted as
i.e
Solution: Use this
您正在尝试迭代通过逻辑上不正确的开始和结束位置的列表中存储的值范围。
其他建议的方法也正确
You were trying to iterate in the range of values stored in the list at starting and end position that was passed, which is logically incorrect.
The other suggested methods are also correct since you specifically said to use the
range
function so think this might be the answer you were looking for