<分区>
Possible Duplicate:
How does Python compare string and int?
一位实习生要求我帮助调试看起来像这样的代码:
widths = [image.width for image in images]
widths.append(374)
width = max(widths)
...当第一行应该是:
widths = [int(image.width) for image in images]
因此,代码选择的是字符串“364”而不是整数 374。python 究竟如何比较字符串和整数?我可以理解将单个字符(如果 python 具有 char
数据类型)与整数进行比较,但我没有看到任何直接的方法来将字符串与整数进行比较。