Why does assigning to True/False not work as I expect?

后端 未结 5 2056
甜味超标
甜味超标 2020-11-27 21:39

As part of answering another question, I wrote the following code whose behaviour seems bizarre at first glance:

print True                    # outputs true         


        
5条回答
  •  广开言路
    2020-11-27 22:01

    You can check whether True/False is a keyword:

    >>> import keyword
    >>> keyword.iskeyword('True')
    False
    

    Since it's not (in my version), assigning True=False just means "True" is another "variable" name.

提交回复
热议问题