#python #pythonprogramming #pythontutorial
https://pokeapi.co/
00:00:00 Pokeapi intro
00:00:40 import requests
00:01:09 pip install requests
00:01:44 url
00:03:17 response.get(url)
00:03:35 response.status_code
00:06:22 display API data
How to connect to an API using Python
import requests
base_url = "https://pokeapi.co/api/v2/"
def get_pokemon_info(name):
url = f"{base_url}/pokemon/{name}"
response = requests.get(url)
if response.status_code == 200:
pokemon_data = response.json()
return pokemon_data
else:
print(f"Failed to retrieve data {response.status_code}")
pokemon_name = "pikachu"
pokemon_info = get_pokemon_info(pokemon_name)
if pokemon_info:
print(f"Name: {pokemon_info["name"].capitalize()}")
print(f"Id: {pokemon_info["id"]}")
print(f"Height: {pokemon_info["height"]}")
print(f"Weight: {pokemon_info["weight"]}")
On this page of the site you can watch the video online Request API data using Python in 8 minutes! ↩️ with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 17 July 2024, share the link with friends and acquaintances, this video has already been watched 311,110 times on youtube and it was liked by 8.2 thousand viewers. Enjoy your viewing!