re: Write a function that shows off something unique or interesting about the language you're using VIEW POST

VIEW FULL DISCUSSION
 

Unique and interesting, but awful

Python 2.X:

>>> True
True
>>> True = False
>>> True
False

Python is full of very tricky things ! I had a lot of fun reading this README which explains them.

 
 

Fortunately it's gone in Python 3:

>>> True
True
>>> True = False
  File "<stdin>", line 1
SyntaxError: can't assign to keyword

:D

 

It still is. bool is a subclass of int:

$ python3
Python 3.6.5 (default, Mar 30 2018, 06:42:10)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(True, int)
True
>>> isinstance(False, int)
True

Shameful mistake, thanks for clarifying ! I meant that they had their own type now, indeed from integer.

Full explanation

Initially, Python used to have no bool type 
(people used 0 for false and non-zero value like 1 for true). 
Then they added True, False, and a bool type, but, for backward
compatibility, they couldn't make True and False constants- they 
just were built-in variables.
 
 

Ah!!! Looks like Python is a distant relative of Javascript!!

code of conduct - report abuse