r/PythonLearning • u/ETL_Pipeline_Dev • 1d ago
Discussion Where do you use None in python
So far I've only really used None in two places:
- With dict.get(), when the key isn't there.
- 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
View all comments
1
u/Potential_Fix_5007 1d ago
It can be important if you(or someone else) want/need to understand your code from month ago.
If you use any kind of check a None is a clear way to show "here is intentinaly no value". A zero (0) An empty string("") Empty List, Set or dict([], {})
All of these are falsy values and would be countet as "False" if you would do something like this:"if value:" or "while value:", but if you use something else than "None" i cant be sure if something else is a empty value by intention, so i may have to understand way more of your Programm just to fix something in a single function.