3 of 151 menu

The str function

The str function creates a new string from the original object. In the first parameter, we specify the object from which we will make a string. In the second optional parameter, you can specify the encoding (by default, UTF-8), and in the third optional parameter, the error type in case of failure to convert to a string.

Syntax

str(the object from which we make a string, [encoding type], [error type])

Example

Let's use the str function to make a string from a number:

num = 1234 txt = str(num) print(txt)

Result of code execution:

'1234'

See also

  • function int,
    which creates the number
  • function float,
    which creates a floating point number
  • function list,
    which creates a list
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline