How to Print a List in Python

0 votes

Hi guys, I've been practicing lists in python recently and I've been having issues trying to print a list in python. I want to print out all the items in a list with the code below, especially the last two lines

def primefind(n):
  mylist = []
  x = 3
  while (x < n/2):
    if ((n % x) == 0):
      mylist.append(x)
      x = x + 2
  for item in mylist:
    print item

I am getting a syntax error when I run this. It highlights "item" in the last line. As far as I can tell it's syntactically correct so I am confused!

Aug 31, 2018 in Python by aryya
• 7,460 points
1,107 views

1 answer to this question.

0 votes

ou are using Python 2.x syntax with a 3.x interpreter. print is a function in Python 3.x, so you should use

print(item)

instead.

answered Aug 31, 2018 by charlie_brown
• 7,720 points

Related Questions In Python

+1 vote
12 answers
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

answered Oct 28, 2020 in Python by Anurag
12,439 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 29, 2018 in Python by SDeb
• 13,300 points
864 views
0 votes
1 answer

List comprehension on a nested list - How to do it in Python?

Not sure what your desired output is, ...READ MORE

answered Nov 21, 2018 in Python by Nymeria
• 3,560 points
1,537 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,470 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,128 views
0 votes
1 answer

How to round a floating point number up to certain decimal place in Python?

This is normal (and has nothing to do ...READ MORE

answered Oct 8, 2018 in Python by charlie_brown
• 7,720 points
2,381 views
0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,720 points
1,681 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP