Skip to main content
 首页 » 编程设计

python之为什么我的函数只循环遍历列表中的三个元素

2025年05月04日9qq号

我试图遍历列表中的所有元素(其中 8 个),但我的函数只提供了其中的 4 个。这是我作为个人项目制作的应用程序。

import urllib 
 
 
def get_followers(): 
    count = 0 
    link = ['http://twitter.com/statuses/user_timeline.xml?screen_name=beratmahmuzlu',     'http://twitter.com/statuses/user_timeline.xml?screen_name=lidiazuin', 'http://twitter.com/statuses/user_timeline.xml?screen_name=kelewele_boham', 'http://twitter.com/statuses/user_timeline.xml?screen_name=AwangHafizam', 'http://twitter.com/statuses/user_timeline.xml?screen_name=BRAYANLVN', 'http://twitter.com/statuses/user_timeline.xml?screen_name=zezol_pl', 'http://twitter.com/statuses/user_timeline.xml?screen_name=brysonwong', 'http://twitter.com/statuses/user_timeline.xml?screen_name=racsozara'] 
    while count < len(link): 
        print link[count] 
        link.pop() 
        count = count + 1 

请您参考如下方法:

您正在弹出列表并使循环基于列表的计数。

尝试使用 for 循环:

for lnk in link: 
    print lnk