简体   繁体   English

python 在 for 循环中使用范围 function 仅迭代偶数

[英]python using range function in for loop to iterate only even number

What arguments shall you pass in a for loop range function to print all even numbers between 11 and 30(included)?您应该在 for 循环范围 function 中传递什么 arguments 以打印 11 到 30(包括)之间的所有偶数?

Code Syntax for i in range(x,y,z): Write the values of xyz in the respective order with a space between each value of x, y, and z. i in range(x,y,z) 的代码语法:以相应的顺序写入 xyz 的值,在 x、y 和 z 的每个值之间有一个空格。

for i in range(x,y,z) where x=12, y=31 & z=2对于范围内的 i (x,y,z),其中 x=12, y=31 & z=2

for i in range(12,31,2):
    print(i)

Output: Output:

12 14 16 18 20 22 24 26 28 30 12 14 16 18 20 22 24 26 28 30

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM