简体   繁体   English

Flask TypeError:“str”和“int”的实例之间不支持“<”

[英]Flask TypeError: '<' not supported between instances of 'str' and 'int'

I'm trying to learn Flash by doing exercise, but I got an error "TypeError: '<' not supported between instances of 'str' and 'int'".我正在尝试通过练习来学习 Flash,但出现错误“TypeError: '<' not supported between 'str' and 'int'”。

from flask import Flask

app = Flask(__name__)

@app.route('/fib/<int:n>/')

def fibo(n):
    n = format(n)
    if n < 2:
        return 1
    return fibo(n -1) + fibo(n -2)

You are trying to make a mathematical comparison between a string and an integer.您正在尝试在字符串和整数之间进行数学比较。 You need to convert n to a number before comparing it to see if it is less than 2. This means changing format(n) to some other function to convert n to a number.在比较 n 是否小于 2 之前,您需要将 n 转换为数字。这意味着将format(n)更改为其他函数以将 n 转换为数字。

Please mark as correct if this helps.如果这有帮助,请标记为正确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NLTK TypeError:&#39;str&#39;和&#39;int&#39;的实例之间不支持&#39;&lt;&#39; - NLTK TypeError: '<' not supported between instances of 'str' and 'int' TypeError:在 Python 中的“str”和“int”实例之间不支持“&gt;” - TypeError: '>' not supported between instances of 'str' and 'int' in Python TypeError:'int'和'str'的实例之间不支持'&lt;=' - TypeError: '<=' not supported between instances of 'int' and 'str' 与“TypeError:'<='在'int'和'str'的实例之间不支持”混淆 - Confused With "TypeError: '<=' not supported between instances of 'int' and 'str'" “TypeError: &#39;&gt;&#39; 在 &#39;int&#39; 和 &#39;str&#39; 的实例之间不受支持”最大值 - "TypeError: '>' not supported between instances of 'int' and 'str'" in max Python-&#39;str&#39;和&#39;int&#39;的实例之间不支持&#39;TypeError:&#39;&lt;=&#39; - Python - 'TypeError: '<=' not supported between instances of 'str' and 'int'' Paramiko TypeError:'int'和'str'的实例之间不支持'&lt;' - Paramiko TypeError: '<' not supported between instances of 'int' and 'str' TypeError: '&lt;=' 在 'str' 和 'int' 的实例之间不支持 - TypeError: '<=' not supported between instances of 'str' and 'int' TypeError: '>' 在表单上的 'int' 和 'str' 实例之间不支持 - TypeError : '>' not supported between instances of 'int' and 'str' on form TypeError:“>”在“str”和“int”的实例之间不受支持 - Python - TypeError: '>' not supported between instances of 'str' and 'int' - Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM