Python 将整数转换为字符串 Jinja
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19161093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:01:45 来源:igfitidea点击:
Convert integer to string Jinja
提问by Glen Swift
I have an integer
我有一个整数
{% set curYear = 2013 %}
In {% if %}
statement I have to compare it with some string. I can't set curYear
to string at the beginning because I have to decrement it in loop.
在{% if %}
声明中,我必须将它与一些字符串进行比较。我不能curYear
在开始时设置为字符串,因为我必须在循环中递减它。
How can I convert it?
我怎样才能转换它?
采纳答案by Glen Swift
I found the answer.
我找到了答案。
Cast integer to string:
将整数转换为字符串:
myOldIntValue|string
Cast string to integer:
将字符串转换为整数:
myOldStrValue|int