Learn Before
Concept
get(key[, default])
The get() method returns the value of a specified key. If the key does not exist, get() returns the optional default value. Usage:
student = { "name": "John", "year": 2, "grade": 95 } student_name = student.get("name") print(student_name) student_age = student.get("age", 19) print(student_age)
The first print statement outputs John. The second print statement outputs 19, as there is no age key in the Dictionary.
0
1
Updated 2021-05-22
Tags
Python Programming Language
Data Science