[英]Python - Returning only first value from a for loop statement
I know this is basic but I have not been able to break this. 我知道这是基本的,但我无法打破这一点。 I have a for loop
that I am trying to execute that returns back 10 rows. 我有一个我想要执行的for loop
返回10行。 How do I limit the loop to only return back first row and not the entire output. 如何将循环限制为仅返回第一行而不是整个输出。
for i in range(10):
print(i)
I cannot change the range value from 10. 我无法从10更改范围值。
Current output: 当前输出:
0
1
2
3
4
5
6
7
8
9
Expected output : 预期产量:
0
Use break
: 使用break
:
for i in range(10):
print(i)
break
And this is not returning anything, it just print the value out. 这不会返回任何东西,只是打印出来的价值。
You can break out of the loop: 你可以摆脱循环:
for i in range(10):
print(i)
break
A simple break
statement would do: 一个简单的break
语句可以:
for i in range(10):
print(i)
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.