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) 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:
Well, you learned something by doing further research which is a good thing!
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"]
['apple', 'banana', 'avocado', 'orange']
I’d also recommend using the terminal and just typing stuff like this in for practice (fun?):
bool() function converts data)
>>> not not 1
>>> not 0
>>> not not not 0
>>> True and False
>>> True or False
>>> True and not True
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!