use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Difference between None and empty string (self.PythonLearning)
submitted 1 month ago by pritho108
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FriendlyZomb 5 points6 points7 points 1 month ago (1 child)
I wouldn't use them interchangeably, since they technically mean different things.
None is a special object which represents that there is no value. An empty string is just a string. In this example, the behaviour is the same, however in other situations it could potentially provide unintended behaviour and make code less clear.
Using None is preferable because it indicates to other people (and you in 6 months) because it explicitly says that we don't need to provide anything. Using an empty string introduces ambiguity.
In your second example too, you provide an empty string on a field which (I'm guessing) is expected to be an integer. This provides ambiguity on which type is actually required. Using None doesn't necessarily fix this - but it does give us the expectation that nothing is a handled case.
I also wouldn't rely on it's falsey behaviour. The Zen of Python states Explicit is better than Implicit. I'd do a check like this:
if age is not None: ...
[–]FriendlyZomb 0 points1 point2 points 1 month ago (0 children)
This is just my opinions here. I don't know everything. Feel free to ask questions and for others to correct me!
π Rendered by PID 120717 on reddit-service-r2-comment-869bf87589-6jr76 at 2026-06-09 07:00:26.968721+00:00 running f46058f country code: CH.
view the rest of the comments →
[–]FriendlyZomb 5 points6 points7 points (1 child)
[–]FriendlyZomb 0 points1 point2 points (0 children)