Script
#!/usr/local/bin/python3.7
school = {"name": "Evergreen Elementary School", "grade": 7, "teacher": "Mr. Johnson", "subject": "Mathematics", "speciality": "Calculus"}
print()
print(school)
print()
person = school["teacher"]
equation = school.get("speciality")
school["speciality"] = "Algebra"
# Loop through the dictionary
for x in school:
print(x)
print()
for q in school:
print(school[q])
print()
for s, t in school.items():
print(s,"\b:", t)
print()
school["city"] = "San Jose"
school["state"] = "California"
print()
print(school)
print()
school.pop("grade")
print(school)
print()
print(len(school))
print()
del school["subject"]
print(school)
print()
Execution
{'name': 'Evergreen Elementary School', 'grade': 7, 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Calculus'}
name
grade
teacher
subject
speciality
Evergreen Elementary School
7
Mr. Johnson
Mathematics
Algebra
name: Evergreen Elementary School
grade: 7
teacher: Mr. Johnson
subject: Mathematics
speciality: Algebra
{'name': 'Evergreen Elementary School', 'grade': 7, 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
{'name': 'Evergreen Elementary School', 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
6
{'name': 'Evergreen Elementary School', 'teacher': 'Mr. Johnson', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
#!/usr/local/bin/python3.7
school = {"name": "Evergreen Elementary School", "grade": 7, "teacher": "Mr. Johnson", "subject": "Mathematics", "speciality": "Calculus"}
print()
print(school)
print()
person = school["teacher"]
equation = school.get("speciality")
school["speciality"] = "Algebra"
# Loop through the dictionary
for x in school:
print(x)
print()
for q in school:
print(school[q])
print()
for s, t in school.items():
print(s,"\b:", t)
print()
school["city"] = "San Jose"
school["state"] = "California"
print()
print(school)
print()
school.pop("grade")
print(school)
print()
print(len(school))
print()
del school["subject"]
print(school)
print()
Execution
{'name': 'Evergreen Elementary School', 'grade': 7, 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Calculus'}
name
grade
teacher
subject
speciality
Evergreen Elementary School
7
Mr. Johnson
Mathematics
Algebra
name: Evergreen Elementary School
grade: 7
teacher: Mr. Johnson
subject: Mathematics
speciality: Algebra
{'name': 'Evergreen Elementary School', 'grade': 7, 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
{'name': 'Evergreen Elementary School', 'teacher': 'Mr. Johnson', 'subject': 'Mathematics', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
6
{'name': 'Evergreen Elementary School', 'teacher': 'Mr. Johnson', 'speciality': 'Algebra', 'city': 'San Jose', 'state': 'California'}
No comments:
Post a Comment