Python – Create String from Integer

Python – Create String from Integer

To create a string from an integer in Python, you can use str() built-in function. Call str() function and pass the given integer as argument. The function returns a string value created using the given integer value.

In this tutorial, we shall go through some examples on how you can take an integer, and create a string from this integer value, in Python.

1. Create string from integer using str() in Python

Given an integer value in n.

Call str() built-in function, and pass n as argument. The function returns a string value. This returned string value is the required output.

Python Program

# Given integer
n = 123456

# Convert integer to string
result = str(n)

# Print resulting string
print("String : " + result)
Run Code Copy

Output

String : 123456

The fact that we could concatenate the result with "String : " in the print() statement proves that the result is a string value.

Summary

In this Python strings tutorial, we learned how to create a new string from a given integer value using str() built-in function.

Related Tutorials

Code copied to clipboard successfully 👍