Skip to content
Advertisement

If I pull data from an API and save it in a variable, does it hit the API every time I call that variable?

I’m grabbing a list from a website using their API and saving it as variable “playlistNames”. In a later function when I call “playlistNames” to manipulate the data, is it making another API call? or is the data just stored locally in the “playlistNames” variable?

Sorry for such a silly question, I can’t seem to google this properly.

Advertisement

Answer

If you saved the API response to a variable, it won’t call the API every time you access that variable.

r = requests.get("https://google.com")
print(r.text) # doesn't call again...
print(r.status_code) # doesn't call again...
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement