如何在Python中连接两个整数? [英] How to concatenate two integers in Python?

查看:589
本文介绍了如何在Python中连接两个整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中连接两个整数(例如:10和20),以获得返回的 1020 值?

How do I concatenate two integer numbers (for example: 10 and 20) in Python to get a returned value of 1020?

推荐答案

在python中执行此操作的最佳方法已在接受的答案中给出-但如果要在jinja2模板中执行此操作-串联运算符为您提供了一种简洁的方法,因为它会查找所有对象的unicode表示形式,因此,您也可以连接整数。

The best way to do this in python was given in the accepted answer - but if you want to do this in jinja2 templates - the concatenation operator ~ gives you a neat way of doing this since it looks for the unicode representation of all objects, thus, you can 'concatenate integers' as well.

也就是说,您可以这样做(鉴于 a = 10 b = 20 ):

That is you can do this (given a=10 and b=20):

{{ a ~ b }}

这篇关于如何在Python中连接两个整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆