Home » How to convert int to string in Python

How to convert int to string in Python

by Online Tutorials Library

How to convert int to string in Python

We can convert an integer data type using the Python built-in str() function. This function takes any data type as an argument and converts it into a string. But we can also do it using the “%s” literal and using the .format() function. Below is the syntax of the str() function.

Syntax –

Let’s understand the following example.

Example – 1 Using the str() function

Output:

<class 'int'>  25  <class 'str'>  25  

Example – 2 Using the “%s” integer

Output:

<class 'int'>  <class 'str'>  

Example – 3: Using the .format() function

Output:

<class 'int'>  <class 'str'>  

Example – 4: Using f-string

Output:

<class 'int'>  <class 'str'>  

We have defined all methods of converting the integer data type to the string type. You can use one of them according to your requirement.


You may also like