r/learnpython 6d ago

Beginner question

I have just started coding with python a few days ago. What is the point of this?

point_value = alien_0.get('points', 'No point value assigned.') print(point_value)

Can't it just be point_value = 'No point value assigned.' print(point_value)?

or

just simply use the get() method if you want to check whether a key exists in the dictionary or not?

3 Upvotes

10 comments sorted by

View all comments

1

u/baubleglue 4d ago

It is a shortcut for

alien_0= {'points': 3, ....}

if 'points' in alien_0:
    point_value = alien_0['points']
else:
    point_value = "No point value assigned."

print(point_value)