0

I am a beginner in python, when I was trying my first python structure code, I meet a question. I tried to add a False to my set, but when I add the False as well as several integers into the set, the elements in the set are only integers without False! As soon as I change one of the integer into float, the False will be an element in the set.

Here's my code:

mySet1 = {1,'cat',0.1,4,False,5}

mySet2 = {1,'cat',0,4,False,5}

mySet1

mySet2

the output is

{0.1, 1, 4, 5, False, 'cat'}

{0, 1, 4, 5, 'cat'}
John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • 1
    `0 == False` in Python. – user2357112 Sep 23 '19 at 02:35
  • This is just a representation detail that you should not care about. Internally ``True`` and ``False`` are int constants. If you do ``print(False == 0)`` you will see it prints ``True``. Plus, if you do ``print({0, False}, {False, 0})`` you will see ``{0} {False}``, so the order may influence what gets printed, but again, internally it's all the same. – Mike Scotty Sep 23 '19 at 02:35
  • [Related](https://stackoverflow.com/questions/2764017/is-false-0-and-true-1-in-python-an-implementation-detail-or-is-it-guarante) – Mike Scotty Sep 23 '19 at 02:41

0 Answers0