[英]How to make iter method of a class return a value without running the for loop?
[英]How return a list of number without iter?
嗨所以我想知道如何通過循環獲取數字列表
例子我試試
i = 1
while i <= 5:
print(i)
i = i + 1
但他像這樣迭代數字
1
2
3
4
5
這就是我想要的
i = 1
while i <= 5:
print(i)
i = i + 1
1 , 2 , 3 , 4 , 5
所以我必須做什么
>>> print(*range(1, 6), sep=' , ')
1 , 2 , 3 , 4 , 5
對於此示例,您不需要循環。
也許您可以在代碼的第 3 行將print(i)
print(i, end=", ")
另外,我認為 Ravan 對您的問題的解決方案更加 Pythonic。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.