APIs (Application Programming Interfaces) allow you to interact with other software systems. In Python, the requests
library is commonly used to interact with APIs.
Here’s how you can make a simple GET request to an API:
import requests
response = requests.get("https://api.github.com/users/octocat")
data = response.json() # Parse JSON response
print("User data:", data)
This code fetches the data from GitHub's API and parses the JSON response to extract user information.
Write a program that fetches the weather data from a public weather API and prints the current temperature in your city.
Answers: The requests
library is used to make HTTP requests. You can parse JSON responses with the response.json()
method.