Danrex
Danrex

Reputation: 1655

Iterate through a list

Very simple problem. Sorry I am new. I have this code below:

list = ['edward', 'jason', 'john']
for i in list:
    print list

and it produces:

john

Why do I only get the last name? I want all of them. ie.

edward
jason
john

Upvotes: 0

Views: 90

Answers (1)

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 250891

You should print i not list:

lis = ['edward', 'jason', 'john']    #don't use list as a variable name
for i in lis:
    print i

Upvotes: 5

Related Questions