Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNoor Elharty
2,630 PointsCan someone explain this (none) part ?
I don't under this none part ? Is it equivalent to empty string or what , i don't fully understand it's it's purpose ... If someone can explain it to me , would be great ... Thanks
1 Answer
Mark Kastelic
8,147 PointsNone is a special type all unto itself. In fact, if you use the type( ) function in your interpreter you'll see:
>>> type(5)
<class 'int'>
>>> type('Mark')
<class 'str'>
>>> type(None)
<class 'NoneType'>
So, an integer (5) belongs to the 'int' class, a string ('Mark') shows it's in the 'str' class, and None belongs to its own class, 'NoneType' Now at the very end of the video, Kenneth mentions that he could have chosen something else to set the value of position to if the user did not enter a valid index and hence an exception was thrown, such as an empty string or -1 (in which case the program would always insert the new item at the end of the list). None by the way, is also what is always returned by any function that does not explicitly return a value (i.e., if the function just prints something). In summary, None as used here, is a clear and unambiguous way to write code that reads, "position was not set to a valid index value by the user." We can easily check later if position == None to determine how to handle this case. Hope this helps.