Python 2.x gotchas and landmines

后端 未结 23 2176
北恋
北恋 2020-11-28 17:47

The purpose of my question is to strengthen my knowledge base with Python and get a better picture of it, which includes knowing its faults and surprises. To keep things sp

23条回答
  •  有刺的猬
    2020-11-28 18:24

    Due to 'truthiness' this makes sense:

    >>>bool(1)
    True
    

    but you might not expect it to go the other way:

    >>>float(True)
    1.0
    

    This can be a gotcha if you're converting strings to numeric and your data has True/False values.

提交回复
热议问题