Python 拆分字符串不可损坏类型

Python 拆分字符串不可损坏类型,python,python-3.x,Python,Python 3.x,我以前从未在Python中拆分字符串,所以我不太确定这里出了什么问题 import pyowm owm = pyowm.OWM('####################') location = owm.weather_at_place('Leicester, uk') weather = location.get_weather() weather.get_temperature('celsius') temperature = weather.get_temperature('cels

我以前从未在Python中拆分字符串,所以我不太确定这里出了什么问题

import pyowm

owm = pyowm.OWM('####################')

location = owm.weather_at_place('Leicester, uk')
weather = location.get_weather()
weather.get_temperature('celsius')
temperature = weather.get_temperature('celsius')

print(temperature[5:10])
收到错误

sudo python weather.py
Traceback (most recent call last):
File "weather.py", line 10, in <module>
print(temperature[5:10])
TypeError: unhashable type
sudo python weather.py
回溯(最近一次呼叫最后一次):
文件“weather.py”,第10行,在
打印(温度[5:10])
TypeError:不可损坏的类型

get\u temperature
返回一个字典,然后尝试使用不可散列的
切片
对象对其进行索引。e、 g

>>> hash(slice(5, 10))                                                                         
Traceback (most recent call last):                                                             
  File "<stdin>", line 1, in <module>                                                          
TypeError: unhashable type

您是否认为
温度
是一个字符串?这不是一根绳子。对我来说,这看起来像是一句口头禅。@user2357112我在黑暗中开始使用Python,谢谢你,我将尝试从这里找出答案,并让你知道我开始了;)不要将字典转换为字符串,然后将其切分,字典的顺序不能保证,你很可能会从中得到垃圾。@tommy.carstensen,嗯?字符串、整数和浮点是可散列的,列表是不可散列的。@NathanK您认为
get\u temperature
会返回字符串的原因是什么?为什么不使用
float
int
?谢谢你,现在就可以了。我不知道字典的类型,我想是时候把我的Python书拿出来了:D
temperature['temp']