Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Yoo Song Won

For loop in Python

It means for every item in cmds it will perform that print statement 

 

So for example, heres another for loop:

x = [a,b,c,d]

for i in x:
	print(i)
    
    
#output#

a
b
c
d

 

Recommended Posts

Posted · Original PosterOP

I'm a bit confused on what the fourth line and the "i" part of the "for i in cmds:" section of this code does. 

 

Does it mean "every element in the list cmds" of which then is printed?

 

Thanks in advance.

image.png.0101be87d3e2b0e468c9842f73ae5f0c.png

Link to post
Share on other sites
Posted · Best Answer

It means for every item in cmds it will perform that print statement 

 

So for example, heres another for loop:

x = [a,b,c,d]

for i in x:
	print(i)
    
    
#output#

a
b
c
d

 


𝓗𝓲 𝓱𝓸𝔀 𝓪𝓻𝓮 𝔂a

Link to post
Share on other sites
Posted · Original PosterOP
Just now, Slottr said:

It means for every item in cmds it will perform that print statement 

 

So for example, heres another for loop:


x = [a,b,c,d]

for i in x:
	print(x[i])
    
    
#output#

a
b
c
d

 

Thanks a lot!! Appreciate it!

Link to post
Share on other sites
On 3/27/2019 at 2:41 PM, Yoo Song Won said:

Thanks a lot!! Appreciate it!

Realized I made a small goof in the print statement, should be:

print(i)

#not

print(x[i])

 


𝓗𝓲 𝓱𝓸𝔀 𝓪𝓻𝓮 𝔂a

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×