Python - Structured Data Files
You want to save a Python dictionary {'a': 1, 'b': 2, 'c': 3} to a JSON file and then read it back. Which code snippet correctly does this and prints the value of key 'b'?
You want to save a Python dictionary {'a': 1, 'b': 2, 'c': 3} to a JSON file and then read it back. Which code snippet correctly does this and prints the value of key 'b'?
import json
with open('file.json', 'w') as f:
json.dump({'a': 1, 'b': 2, 'c': 3}, f)
with open('file.json', 'r') as f:
data = json.load(f)
print(data['b']) does this correctly.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions