Python:Numbers

From wiki
Revision as of 15:43, 27 January 2022 by Hdridder (talk | contribs) (Created page with "NOTE: Numbers starting with 0 are interpreted as octal number. Look at this: <syntaxhighlight lang=python> >>> a = 0123 >>> print(a) 83 >>> type(a) <type 'int'> </syntaxhighl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

NOTE: Numbers starting with 0 are interpreted as octal number.

Look at this:

>>> a = 0123
>>> print(a)
83
>>> type(a)
<type 'int'>
int(x)
Convert x into an integer
hex(x)
Convert x into an hexadecimal number 0x....
oct(x)
Convert x into an octal number 0....

See Python:Strings#Advanced for conversions by format.