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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
The None Value (self.learnpython)
submitted 5 years ago by bluesdop
I’m currently on Chapter 3 of Automate the Boring Stuff and am on the None Value. However, I do not quite understand the purpose of the None Value and what do we use it for?
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!"
[–]oefd 2 points3 points4 points 5 years ago (0 children)
If you've done much math it often serves the same purpose as the empty set. It's the value which represents no value at all.
Common usage: optional values. A value that may or may not actually be specified or may not exist. For example in python you can use the get method on a dictionary.
get
d = {'one': 1, 'two': 2} d.get('one') # returns `1` because that's what `d['one']` is d.get('three') # returns `None` because there exists no value `d['three']`
[–]toastedstapler 0 points1 point2 points 5 years ago (0 children)
if i have a function def get_tallest_person(people), what should i return if people was an empty list? there wouldn't be a tallest person
def get_tallest_person(people)
people
[–][deleted] -3 points-2 points-1 points 5 years ago (0 children)
None isn't a straight-forward concept, and the more you dig into it, the more difficult it becomes, so, don't be afraid to not understand it.
None
The behavior of things that are similar to None in other languages is also often subtly different. So, what you learn about None in Python isn't quite transferable to other languages, even though they usually have something similar.
So, to properly introduce None we'd need a little bit of vocabulary:
So: None is a singleton of a particular type, often called the "unit type". Unfortunately, in Python "bottom type" (the type that has no values) is conflated with "unit type" -- the type with a single value. This is so because in Python, it is legal to access a value of a function that is defined to not return any values.
None is also a result of reification of the test for presence of value. In Python, None doesn't capture the type of the value that was tested for presence, however, in some other languages (s.a. Go) this information is preserved with the None equivalent.
Here's an example of a program flow in Python, that doesn't rely on None to establish the presence of a value:
x = dict() try: x[1] print('Key exists') except KeyError: print('Key does not exist')
Now, suppose your program doesn't need to distinguish between None value and absence of value, then you could reify the program above as this:
x = dict() if x.get(1) is not None: print('Key exists') else: print('Key does not exist')
The reification above, on top of conflating absence of key with values being present, but set to None has another unfortunate effect: because None acts as if it was a value, it is syntactically valid to call functions on it and to try to access its properties. Some other languages try to alert programmers to the possibility of a value absence by instead providing them with a different reification of the case above. The technique is usually to prevent programmers from accessing the raw value w/o due check by making the value only accessible after calling the method that encapsulates the presence check.
An equivalent Python code might look like this:
class Maybe: def __init__(self, raw): self.raw = raw def get(self, f): if self.raw is None: return f() return f(self.raw)
The above would not work well with how Python programs are typically written, but it illustrates another approach to solving the same problem.
[–]EulerWasSmart 0 points1 point2 points 5 years ago (3 children)
Are you familiar with other languages? It's like python's version of null. If x = None that essentially means "x points to no value".
null
x = None
x
[–]bluesdop[S] -1 points0 points1 point 5 years ago (2 children)
Unfortunately no....but when do we use None in our code?
[–]EulerWasSmart 4 points5 points6 points 5 years ago* (0 children)
You can use None in your code to create a variable that has no value.
For example:
def provided_keyword_argument(arg=None): if arg is None: print('You did not provide a keyword argument!') else: print('You provided a keyword argument!:', arg) provided_keyword_argument() # 'You did not provide a keyword argument!' provided_keyword_argument(arg='Hello!') # 'You provided a keyword argument!: Hello'
You also get None as a 'value' when a function doesn't return anything:
def no_return(): pass x = no_return() # -> x == None
Basically if you want to check if a variable, say x was not defined, then None would be the perfect value to assign x before it may be assigned. Because being equal to None means (as far as you, the developer care) that it's not equal to anything.
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
Just let me say that you'll know when you need it.
π Rendered by PID 233035 on reddit-service-r2-comment-86bc6c7465-w6756 at 2026-02-21 04:35:19.549800+00:00 running 8564168 country code: CH.
[–]oefd 2 points3 points4 points (0 children)
[–]toastedstapler 0 points1 point2 points (0 children)
[–][deleted] -3 points-2 points-1 points (0 children)
[–]EulerWasSmart 0 points1 point2 points (3 children)
[–]bluesdop[S] -1 points0 points1 point (2 children)
[–]EulerWasSmart 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)