PYTHON LESSON 29 OF 32

APIs & the web

An API lets programs communicate. HTTP GET usually retrieves data; status codes indicate outcomes. Validate responses and handle timeouts. This local example parses a sample API response without needing a live server.

हिन्दी में समझें

API प्रोग्रामों को संवाद करने देता है। HTTP GET सामान्यतः डेटा लेता है। स्टेटस कोड परिणाम बताता है। उत्तर जाँचें, timeout सँभालें। यह नमूना बिना लाइव सर्वर चलता है।

अभ्यास: नमूने का temperature 30 करें और नया मान प्रिंट करें।

Hinglish mein samjhein

API programs ko baat karne deta hai. GET usually data leta hai. Status code result batata hai. Response validate aur timeouts handle karo. Yeh sample live server ke bina chalta hai.

Practice: Sample temperature 30 karo aur nayi value print karo.

A small Python example

import json
response_text = '{"status": "ok", "temperature": 28}'
data = json.loads(response_text)
print(f"Temperature: {data['temperature']} C")

The browser playground runs real Python with Pyodide. Use sample variables instead of interactive input(). Browser package support differs from desktop Python.

Try this example in the Python playground →

Practise this idea

Change the sample temperature to 30 and print the new value.

Check answer & explanation
import json
response_text = '{"status": "ok", "temperature": 30}'
data = json.loads(response_text)
print(f"Temperature: {data['temperature']} C")

The parsed temperature comes from the sample JSON response. Changing it to 30 changes the value used in the formatted message.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

HTTP GET usually…

  1. Retrieves data
  2. Deletes all files
  3. Compiles Python
Check the quiz answer

Retrieves data

GET requests a representation of a resource.

References & corrections

Use the official Python documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.