In "Intro to Lists" (Python 3) I think you guys should mention to learners that the Boolean True and False can also be interpreted as 1 and 0

As I said in the title, I think it would be useful to include this small observation for learners.

I say that because I tried to make a list like the following: my_list[1, True] and remove the boolean value using its position on the list: my_list.remove(my_list[1]) and it, to my surprise (I’m a begginer), the return was [True], which meant that the integer 1 got removed.

After reading more about it, in the following link: https://teamtreehouse.com/community/remove-method-removes-1-instead-of-true-from-list, I learned that it works like that because the method .remove searched for “True” (boolean) and because 1 is also equivalent to True, it removed the first result of “True” it found.

I believe this could teach a valuable piece of how Python works and, at the same time, prevent future “bugs” or the code not working as intended, for future programmers/learners.

Here is a link to the lesson:

https://www.codecademy.com/courses/learn-python-3/lessons/create-python-list/exercises/list-methods

Thanks!

Well, you learned something by doing further research which is a good thing! :slight_smile:
You bring up a decent point, but, as always, don’t solely rely on CC for your programing language learning.

Also, isn’t this (1,0, True, False) mentioned in the data types or control flow section?

Side note: the list method, .remove() takes one parameter, an object. If the list has more than one of the same item, it removes the first instance of said item.

>>> my_list = ["orange", "apple", "banana", "avocado", "orange"]
>>> my_list.remove("orange")
>>> print(my_list)
['apple', 'banana', 'avocado', 'orange']

I’d also recommend using the terminal and just typing stuff like this in for practice (fun?):
(The bool() function converts data)

>>> bool(1)
True
>>> bool(0)
False
>>> 
>>> not not 1
True
>>> not 0
True
>>> not not not 0
True
>>> True and False
False
>>> True or False
True
>>> True and not True
False

1 Like

I don’t think it was, at least not until the specific lesson I mentioned (if I recall correctly!)

Thanks for the reply, I appreciate it!

1 Like