sophialeo1314
sophialeo1314
采纳率0%
2016-04-16 09:31 阅读 2.8k

为什么这段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 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')])
    
    点赞 评论 复制链接分享
  • qq_40523298 qq_40523298 2019-04-13 15:57

    def delete(word_list):
    if word_list:
    for i in word_list:
    for j in range(len(i)):
    if i[j] == 'stop':
    word_list.remove(i)
    return word_list

    点赞 评论 复制链接分享

相关推荐