How to get 1d:price_change_pct in Python

I am new to Python and APIs, so I apologize in advance if the wording I’m using is very noobish or outright wrong! So far getting basic data, such as currency, rank, price is outputting correctly. However, I can’t seem to get the price change percentages (“price_change_pct”) for 1d, 7d, 30d etc. It appears that that data is within a dictionary with time interval being the key. Is that right?

How would I change the following print statement for price (which outputs correctly) so that it outputs the 1d percentage change. (“x” is for x in api:)

print(“Current price: ${0:.8f}”.format(float(x[“price”])))

I’ve tried quite a few methods but I always get invalid syntax or some unhashable type error.

Thanks in advance.

I am not familiar with python but I would expect x["1d"]["price"] to work. Ensure your url includes the interval param with the interval size you’re asking for.

This works in Ruby:

require 'net/http'
require 'json'
uri = URI(",ETH,XRP&interval=1d,30d&convert=EUR&per-page=100&page=1")
data = JSON.parse Net::HTTP.get(uri)
p data[0]["1d"]["price_change_pct"]

x[“1d”][“price_change_pct”] works! Thank you so much!