为什么值与声明元组时的值不同?

时间:2019-07-04 15:01:28

标签: python tuples

我试图了解我的代码正在发生什么,但是我无法获得解决方案。

这是我的代码:

multipolygon = ((
    (-58.89198482 -13.38147202, -58.89189251 -13.38147271, -58.89189321 -13.38156309, -58.89198552 -13.3815624,
     -58.89207783 -13.38156171, -58.89217014 -13.38156102, -58.89226245 -13.38156032, -58.89235476 -13.38155963, 
     -58.89244706 -13.38155894, -58.89253937 -13.38155825, -58.89263168 -13.38155756, -58.89263097 -13.38146719, 
     -58.89253867 -13.38146788, -58.89244636 -13.38146857, -58.89235405 -13.38146926, 
     -58.89226174 -13.38146995, -58.89216943 -13.38147064, -58.89207712 -13.38147133, 
     -58.89198482 -13.38147202)
    ), 
 (
    (-58.89484849 -13.38172171, -58.89484919 -13.38181209, -58.8949415 -13.38181139, 
   -58.89503381 -13.3818107, -58.89512612 -13.38181001, -58.89521843 -13.38180932, 
   -58.89521772 -13.38171894, -58.89531003 -13.38171825, -58.89540234 -13.38171756, 
   -58.89540163 -13.38162718, -58.89540092 -13.38153681, -58.89540022 -13.38144644, 
   -58.89530791 -13.38144713, -58.8952156 -13.38144782, -58.89512329 -13.38144851, 
   -58.89503098 -13.3814492, -58.89493868 -13.3814499, -58.89484637 -13.38145059, 
   -58.89484707 -13.38154096, -58.89484778 -13.38163134, -58.89484849 -13.38172171)
    )
)
for poly in multipolygon:
    print(poly)

问题是当我打印多面体时,值正在更改。 输出如下:

(-72.27345684, -72.27336522, -72.27345629999999, -72.27354792, -72.27363954, -72.27373116, -72.27382277, -72.27391439, -72.274006, -72.27409762, -72.27418924, -72.27409816, -72.27400655, -72.27391493, -72.27382331, -72.27373169, -72.27364007, -72.27354845, -72.27345684)
(-72.27657020000001, -72.27666128, -72.27675289, -72.27684451, -72.27693613, -72.27702775, -72.27693666, -72.27702828, -72.2771199, -72.27702881, -72.27693773, -72.27684666, -72.27675504, -72.27666342, -72.2765718, -72.27648018000001, -72.27638858, -72.27629696, -72.27638802999999, -72.27647912, -72.27657020000001)

为什么会这样?

3 个答案:

答案 0 :(得分:2)

看起来您在元组中缺少逗号,这会导致一些值被减去

从您的代码中: -58.89484849 -13.38172171

我假设您的意思是-58.89484849,-13.38172171?

否则-58.89484849 -13.38172171 = 72.2765702与打印值匹配

答案 1 :(得分:1)

它可以进行数学运算,因为这就是数据结构中的内容

-58.89198482 -13.38147202 = -72.27345684

答案 2 :(得分:1)

正在发生的事情是您在打印之前减去(-58.89189251 -13.38147271)