How to Concatenate Strings and Integers in Python?

Estimated read time 1 min read

To concatenate strings and integers in Python, you need to convert the integer to a string using the str() function before concatenating it with a string. Here’s an example:

string = "Hello"
integer = 123

concatenated_string = string + str(integer)

In this example, we have a string string and an integer integer. Before concatenating them, we use the str() function to convert the integer to a string. Then, we can concatenate the string and the converted integer using the + operator. The resulting concatenated string is assigned to the concatenated_string variable and printed.



By converting the integer to a string, you can concatenate it with other strings using the + operator. The str() function is a convenient way to convert various data types, including integers, to string representation in Python.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply