Skip to main content
 首页 » 编程设计

python之在 python 中打印列表

2025年05月04日10lori

<分区>

我在尝试用 Python 打印列表时遇到问题。我想用以下代码打印出列表中的所有项目,特别是最后两行。

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 

当我运行它时出现语法错误。它在最后一行突出显示“item”。据我所知,它在语法上是正确的,所以我很困惑!甚至这个网站也显示了与我使用的相同的语法 http://effbot.org/zone/python-list.htm#looping

我哪里出错了?