程序员文章、书籍推荐和程序员创业信息与资源分享平台

网站首页 > 技术文章 正文

Python基础编程20例之七:filter过滤,筛选奇数

hfteth 2025-07-01 19:45:34 技术文章 6 ℃

20230115星期日:



list_value = [1,2,3,4,5,6,7,8,9]
def is_qishu(n):
    if n % 2 == 1:
        return True
    else:
        return False
result = filter(is_qishu,list_value)
print(list(result)) # [1, 3, 5, 7, 9]

Tags:

最近发表
标签列表