Skip to content

Instantly share code, notes, and snippets.

@justxor
Created May 31, 2022 06:47
Show Gist options
  • Save justxor/b97d53a558e383c75fb28de4e0cf11ba to your computer and use it in GitHub Desktop.
Save justxor/b97d53a558e383c75fb28de4e0cf11ba to your computer and use it in GitHub Desktop.
person = {'name': 'Phill', 'age': 22}
print('Name: ', person.get('name'))
print('Age: ', person.get('age'))
# value is not provided
print('Salary: ', person.get('salary'))
# value is provided
print('Salary: ', person.get('salary', 0.0))
#Вывод
Salary: None
Traceback (most recent call last):
File "", line 7, in
print(person['salary'])
KeyError: 'salary'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment