⊗pyPmBsCTN 32 of 208 menu

Converting to Integers in Python

To convert a string to a number, you need to use the int function. Let's make two string variables numeric and get their sum:

txt1 = '1' txt2 = '2' res = int(txt1) + int(txt2) print(res) # the number 3

You can use the conversion command directly in the function call:

print(int('123')) # the number 123

Given a variable:

txt = '123'

Convert the variable value to an integer.

Given variables:

txt1 = '123' txt2 = '456'

Find the sum of the values ​​of these variables.

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