sophialeo1314 2016-04-16 09:31 采纳率: 0%
浏览 2969

为什么这段PYTHON程序的输出为None?

def delete(word_list):

if word_list:

    for i in word_list:

        if i[0] == 'stop':

            word_list.remove(i)

print delete([('noun', 'bear'),('stop', 'the')])

请各位帮忙看看,多谢

  • 写回答

2条回答 默认 最新

  • cxsmarkchan 2016-04-17 15:26
    关注

    delete函数没有返回值,所以是None。改成这样:

    def delete(word_list):
        if word_list:
            for i in word_list:
                if i[0] == 'stop':
                    word_list.remove(i)
            return word_list
    print delete([('noun', 'bear'),('stop', 'the')])
    
    评论

报告相同问题?