python - 我收到类型错误 : '<' not supported between instances of 'str' and 'int'

标签 python string int

在Python中,当我在spyder Ide中尝试使用min()函数打印列表中的最小值时,会出现错误。但是当我在 pycharm 中运行相同的代码时,它运行良好。我应该怎么做才能让它在spyder Ide上打印?

这是我的代码

lst = [101,754,'abcd','xyz','m']
Printing("Minimum value in List:", min(lst))

这会产生错误:

TypeError: '<' not supported between instances of 'str' and 'int'

最佳答案

很可能您的spyder IDE 在您的系统中默认为Python 3,而您的 PyCharm 项目默认为Python 2。

在 Python 3 中,strint 实例之间的排序未定义并引发异常。在 Python 2 中,IIRC 它根据两个对象的地址 (id()) 返回 True 或 False。

关于python - 我收到类型错误 : '<' not supported between instances of 'str' and 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53616245/

相关文章:

c - 复制一个字符串数组(或将它们复制到另一个数组)?

java - 检查一个字符串是否可以在没有 try-catch 的情况下解析为 Long?

java - 这个循环有效,但是还有另一种方法可以在 java 中进行循环吗?

c - 将 32 位 int 存储到 char 缓冲区

c# - 为什么 char 数组在控制台上显示内容,而 string 和 int 数组不在 c# 中?

python - 为什么这些字符串不相等? (Python)

python - 如何计算 Pandas Dataframe 中所有列的哈希值?

Python CFFI 将结构转换为字典

python - 如何在lightGBM中设置metric输出的频率?

c++ - 如何将指定行数作为输入?