I am just curious to understand JSON and Dict in Python more deeply.
I have a JSON response from a server like this:
`{"city":"Mississauga","country":"Canada","countryCode":"CA"}`
And I want to work with it as a dictionary. For this, I use .json()
function. Why can I get data by using res.json()['city']
, but cannot do it with req.json().city
?
In Python, dictionary values are not accessible using the my_dict.key
syntax. This is reserved for attributes of the dict
class, such as dict.get
and dict.update
. Dictionary values are only accessible via the my_dict[key]
syntax.