How to concatenate two integers in Python?

前端 未结 14 1907
南旧
南旧 2020-12-15 03:51

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

相关标签:
14条回答
  • 2020-12-15 04:33

    Just to give another solution:

    def concat_ints(a, b):
        return a*(10**len(str(b)))+b
    
    >>> concat_ints(10, 20)
    1020
    
    0 讨论(0)
  • 2020-12-15 04:34

    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.

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

    {{ a ~ b }}
    
    0 讨论(0)
提交回复
热议问题