ScanSkill

int data type

int data type represents the numbers that are in the range -2147483648 through 2147483647. The numbers that are outside of this range are normally called long integers.

Numbers are created by numeric literals or as the result of built-in functions and operators. Plain integer literals (including binary, hex, and octal numbers) yield plain integers unless the value they denote is too large to be represented as a plain integer, in which case they yield a long integer. Integer literals with an ‘L’ or ‘l’ suffix yield long integers (‘L’ is preferred because 1l looks too much like eleven! :0).

Constructors

  • int(): It converts an expression into an integer.
  • literal syntax: It is used to initialize a new instance of the int type. e.g.
>>> 7
7
>>> 7+7
14
>>> 2**30
1073741824
>>> -1073741824
-1073741824

Examples

  • Valid integer literals:
>>> 0
0
>>> 7
7
>>> -13
-13
>>> 135792468
135792468
>>> y=50000000000000000000000000000
50000000000000000000000000000
  • Binary, octal, and hexadecimal
>>> 0b11011000 # binary
216
>>> 0o12 # octal
10
>>> 0xd # hexadecimal
13