r/PythonLearning • • 1d ago

Discussion Where do you use None in python

So far I've only really used None in two places:

  1. With dict.get(), when the key isn't there.

  2. With del in classes. I set a variable to None so the object gets cleaned up.

Where else do you use it? Do you use it as a default value for function arguments, or for missing data?

 

I'm curious how people use it in real projects.

14 Upvotes

15 comments sorted by

View all comments

1

u/HanTheGreatInventor 20h ago

Default value ofc.

func(x=None):
x=5 if x is None else x

1

u/Money_Ad_5277 1h ago

Not like that, but yeah. Also python have "or" operator, so
x = x or 5
Not sure when it was added but cool coalesce operator