4 of 151 menu

The int function

The int function creates a new number from the original object. In the first parameter, we specify the object from which we will make a number. In the second optional parameter, you can specify the number format (by default, 10).

Syntax

int(number or string, [number format])

Example

Let's use the int function to make a number out of a string:

txt = '123' num = int(txt) print(num)

Result of code execution:

123

Example

Now let's convert the string value into an octal number:

txt = '0o12' num = int(txt, base=8) print(num)

Result of code execution:

10

See also

  • function float,
    which creates a floating point number
  • function str,
    which creates a string
  • 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