简体   繁体   English

在 python 中有两个不同索引的循环?

[英]For loop with two different indexes in python?

I have the following loop in java我在 java 中有以下循环

double f,x,y;
int i;
for(i=0, f=0.01; i<100 && f<1.0; i++,f+=0.01)
{
     x=y*i+y*f;
     system.out.println("x = " +x,i , f);
}

But I would like to have 2 different indexes at once in it.但我想一次有 2 个不同的索引。

try this one试试这个

for i, j in zip(range(100), [(x/10) for x in range(100)]):
  #print (i, j)
  #your code

For this example, you can define f in terms of i :对于此示例,您可以根据i定义f

for i in range(0, 100):
    f = (i + 1) / 100.0
    ...

You can use a while loop instead.您可以改用 while 循环。

f = -1
i = 0
x = -1
y = -1
while (i < 100 and f < 1.0):
    x = y * i + y * f
    print('x = {} {} {}'.format(x, i, f))
    i += 1
    f += 0.01

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

相关问题 在for循环中打印出两个索引之间的值 - Printing out values between two indexes in for loop 如何检查两个不同数组的相等索引并输入正确的值 - How to check the equal indexes of two different Arrays and put the correct value hibernate 搜索索引一个实体到两个不同的索引 - hibernate search indexing one entity to two different indexes 访问嵌套的 For 循环索引 - Accessing Nested For Loop Indexes 替换索引而不循环 - Replace the Indexes without Loop Java:递归循环的组合,里面有不同的FOR循环; 输出:FOR循环索引 - Java: Combination of recursive loops which has different FOR loop inside; Output: FOR loops indexes 如何在循环中使用多个条件来比较字符串的不同索引? - How can I use several conditions in a loop to compare different indexes of a string? 为什么我的循环输出两个不同的结果? - Why is my loop outputting two different results? 如何使用 Binary Search 打印两个不同 ArrayLists 中匹配索引的所有字符串? - How do I print all strings from matching indexes in two different ArrayLists using Binary Search? 如何使用 Java 在每个 pdf 文件中获取具有不同索引的两个字符串之间的字符串 - How to get a String between two Strings with different indexes in each pdf file using Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM