Python3 实现两个列表的值相减

备忘

Python3 列表的高级用法应该是使用列表推导式,而不是 for 循环。
这里主要是类型转换问题。

# coding: utf-8
from decimal import Decimal

__author__ = 'Evan'


d_list = [Decimal('837500.00'), Decimal('837500.00'), None]

c_list = [234400.0, 133230.0, 12.0]

for k in range(3):
    if d_list[k] is not None:
        print("索引", k, Decimal(d_list[k]) - Decimal(c_list[k]))
    else:
        print("索引", k, d_list[k])

猜你喜欢

转载自blog.csdn.net/Yuyh131/article/details/85010801