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

2015-12-22 21:22:34 +08:00
 panda0

如图

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

1968 次点击
所在节点    Python
7 条回复
shakespaces
2015-12-22 21:24:28 +08:00
拼写不忍直视
mengzhuo
2015-12-22 21:32:30 +08:00
天啊……楼主你还是回去看看书吧
不……不是那本 Python 手册,我说的是英语书!
Arthur2e5
2015-12-22 21:46:40 +08:00
……你想不想知道有個內置函式叫做 sum(*iterable)?
bdbai
2015-12-22 22:37:50 +08:00
> 请在写下问题之后多多检查自己的拼写,这是对阅读你的问题的其他人起码的尊重。

/t/10686
stillwater
2015-12-22 23:09:52 +08:00
转换成 float 再相加吧
ericls
2015-12-23 00:15:21 +08:00
@shakespaces 估计是手滑 uy 在 yt 旁边
latyas
2015-12-23 03:52:37 +08:00
让 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.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/245467

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX