推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
sunweiliv2
V2EX  ›  Python

如何定义 通过输入 上限和下限 ,筛选数据 的函数

  •  1
     
  •   sunweiliv2 · Jan 7, 2018 · 2120 views
    This topic created in 3187 days ago, the information mentioned may be changed or developed.
    想定义一个函数:
    输入上限和下限 的值,能筛选出数据中的值。

    # a 下限,b 上限
    data=[5,6,7,8,9]
    def factor_value(a,b):
    for a,b in data:
    if a < data
    elif b > data
    return a+b
    factor_value(4,10)

    我的思路是 a、b 值遍历 data 后判断大小。
    返回的是 if a < data 语法错误。

    本人初学,思路和语法基础都不够。有大神能写一个吗?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2414 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 19ms · UTC 11:35 · PVG 19:35 · LAX 04:35 · JFK 07:35
    ♥ Do have faith in what you're doing.