开发者

How to pass value for python for loop?

开发者 https://www.devze.com 2022-12-14 07:55 出处:网络
In C/C++: for(int i=0;i<=5;i++) In Python: for i in range(0,5) Question is: s=[1,2,3,4,1] for i in s: for j in s:

In C/C++:

for(int i=0;i<=5;i++)

In Python:

for i in range(0,5)

Question is:

s=[1,2,3,4,1]

for i in s:
    for j in s:

Here i wanna make second for loop j=1 (j value should be start with 1 like this s[1]=2).How do 开发者_Python百科i pass that value.


You should ask this on stackoverflow, but the answer is (if I got you right):

for i in s:
   for j in s[1:]:

Read this chapter about lists in python, this will help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消