user3320685
user3320685

Reputation:

How to print multiple times from a list in Python

Have a school assignment and I have everything done. I was revising my code and realized the last part should be cleaned up a bit, but I don't know how. I want to print multiple items from a list so that I don't have to have multiple print lines. They didn't tell me how in the lesson, so I'd appreciate any help! Thanks!

I want to clean up the print lines and convert them to one.

def main():

    favoritethingsList = ["1  Film Production", "2  Photography", "3  Programming", "4  Mountain Biking", "5  Surfing"]

    print(favoritethingsList[0])
    print(favoritethingsList[1])
    print(favoritethingsList[2])
    print(favoritethingsList[3])
    print(favoritethingsList[4])

main()

Thanks!

Upvotes: 0

Views: 1709

Answers (1)

Anshul Goyal
Anshul Goyal

Reputation: 76877

You can use a simple for loop to do this:

def main():
    favoritethingsList = ["1  Film Production", "2  Photography", "3  Programming", "4  Mountain Biking", "5  Surfing"]
    for line in favoritethingsList: print(line)

main()

In case you want to print all of the contents of the list in a single line, use

print(", ".join(favoritethingsList))

Upvotes: 3

Related Questions