Unit: Unit 5: Dictionaries and Sets • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Access values using square bracket notation d[key]
server_node = {
"hostname": "prod-api-01",
"ip_address": "10.0.4.15",
"region": "us-east-1",
"cpu_cores": 16
}
# 1. Access existing keys
host = server_node["hostname"]
cores = server_node["cpu_cores"]
# 2. Check key existence before accessing using 'in'
has_gpu = "gpu_count" in server_node
print("Host:", host)
print("Cores:", cores)
print("Has GPU configured:", has_gpu)