V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
panda0
V2EX  ›  Python

puyhon 文本价格相加 ex:¥23.00+¥20.00

  •  
  •   panda0 · Dec 22, 2015 · 2413 views
    This topic created in 3779 days ago, the information mentioned may be changed or developed.

    如图

    如何实现价格相加,计算价格总和

    image

    shakespaces
        1
    shakespaces  
       Dec 22, 2015
    拼写不忍直视
    mengzhuo
        2
    mengzhuo  
       Dec 22, 2015
    天啊……楼主你还是回去看看书吧
    不……不是那本 Python 手册,我说的是英语书!
    Arthur2e5
        3
    Arthur2e5  
       Dec 22, 2015   ❤️ 1
    ……你想不想知道有個內置函式叫做 sum(*iterable)?
    bdbai
        4
    bdbai  
       Dec 22, 2015 via iPhone
    > 请在写下问题之后多多检查自己的拼写,这是对阅读你的问题的其他人起码的尊重。

    /t/10686
    stillwater
        5
    stillwater  
       Dec 22, 2015
    转换成 float 再相加吧
    ericls
        6
    ericls  
       Dec 23, 2015
    @shakespaces 估计是手滑 uy 在 yt 旁边
    latyas
        7
    latyas  
       Dec 23, 2015   ❤️ 2
    让 lz 难受一下
    sum(map(lambda item: float(re.findall('[\d\.]+', item)[0]), map(lambda x: x.text, i.select['.price_n'])))

    @Arthur2e5 是 sum(iterable)

    sum(iterable, start=0, /)
    Return the sum of a 'start' value (default: 0) plus an iterable of numbers

    When the iterable is empty, return the start value.
    This function is intended specifically for use with numeric values and may
    reject non-numeric types.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5065 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 01:09 · PVG 09:09 · LAX 18:09 · JFK 21:09
    ♥ Do have faith in what you're doing.