/  Technology   /  Converting integer to string in Python

Converting integer to string in Python

Converting integer to string in Python

We can convert an integer into a string using the following ways

 

  • Using str()
  • Using %s
  • Using format()
  • Using f-string
  1. Using str()

This function returns a string version of any object. The object can be of any type int, char, float, etc. If no object is passed, it returns an empty string. 

  1. Using %s keyword:

%s indicates a conversion type of string. It converts the given object to a string using the str() function.

Syntax:  “%s”  %integer

  1. Using .format():

This method returns a formatted representation of the given object controlled by the format specifier. The format specifier specifies which type we are trying to convert the object into.

Syntax:  ‘{}’.format(integer)

  1. Using f-string:

The f-string is literal string interpolation or it’s a more simplified way for string formatting. 

Syntax:  f’{integer}’

Leave a comment