Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate two integers in Python?

How do I concatenate two integer numbers in Python? For example, given 10 and 20, I'd like a returned value of "1020".

like image 986
Fi3n1k Avatar asked Oct 11 '12 11:10

Fi3n1k


People also ask

Can you concatenate integers and strings in Python?

Python supports string concatenation using + operator. In most of the programming languages, if we concatenate a string with an integer or any other primitive data types, the language takes care of converting them to string and then concatenate it.

How do you concatenate integers in a list in Python?

The extend method() adds all the elements of the list till the end. To concatenate the list on integers “+” is used. The print(newlist) is used to get the output.

How do you concatenate numbers?

This means that you can no longer perform any math operations on them. To combine numbers, use the CONCATENATE or CONCAT, TEXT or TEXTJOIN functions, and the ampersand (&) operator. Notes: In Excel 2016, Excel Mobile, and Excel for the web, CONCATENATE has been replaced with the CONCAT function.


1 Answers

Cast both to a string, concatenate the strings and then cast the result back to an integer:

z = int(str(x) + str(y)) 
like image 170
Konstantin Dinev Avatar answered Sep 21 '22 04:09

Konstantin Dinev