我有一堆關於太陽系行星的細節。我應該用Python製作一本字典。對於每個行星,我都有它的半徑,與太陽的距離,衛星的數量,如果存在大氣層,衛星的名稱,如果它是氣體行星等等。使用行星數據創建字典
例如,這裏是水星的數據:
Mercury
Radius - 2,439.7 km
Distance from the sun - 58 million km
Moons - none
Atmosphere? True
Gas planet? False
我將如何使用這些數據來創建一個字典?
到目前爲止,我有:
radius = {} #radius of planets
radius['Mercury'] = 2439.7
radius['Venus'] = 6051.8
radius['Earth'] = 6371.0
radius['Mars'] = 3,396.2
radius['Jupiter'] = 69,911
radius['Saturn'] = 60,268
radius['Uranus'] = 25,559
radius['Neptune'] = 24,764
distance = {} # distance from sun
distance['Mercury'] = 58000000
distance['Venus'] = 108000000
我是繼續此創建一個字典的一切,我有這樣我會爲每個不同類型的數據的不同部分的數據的規劃。
但是,如果這是正確的做法,我不這樣做。有人可以告訴我,如果我走向正確的方向嗎?如果沒有,我將如何解決它?
(a)你不能在數字中使用逗號Python編寫的。 (b)你知道你可以用一個單一的表達式來描述字典,比如'{「Mercury」:2439.7,「Venus」:6051.8,...}',而不用單獨設置每個值,對不對? – jwodder