int

Python

Les entiers ne sont pas limités en taille contrairement à la plus part des langages.

L'entier 17 en décimal peut être écrit :

en binaire (0b) : 0b10001

en octal (0o) : 0o101

en hexadécimal (0x) : 0x11

Les opérations sur les entiers :

  1. + l'addition
  2. - la soustraction (substraction)
  3. * la multiplication
  4. / division rendant un résultat réel (7/5 rend 2.4)
  5. // division rendant un résultat entier (7//5 rend 2)
  6. % le modulo
  7. abs(expression) la valeur absolue (the absolute value)

Plus de précisions sur les entiers (a priori, vous n'en avez pas à vous en soucier).

Il y a une classe numbers.integral avec 3 types d'entiers (cf ci-dessous un extrait du manuel de référence de Python) :

" Plain integers

These represent numbers in the range -2147483648 through 2147483647. (The range may be larger on machines with a larger natural word size, but not smaller.) When the result of an operation would fall outside this range, the result is normally returned as a long integer (in some cases, the exception OverflowError is raised instead). For the purpose of shift and mask operations, integers are assumed to have a binary, 2’s complement notation using 32 or more bits, and hiding no bits from the user (i.e., all 4294967296 different bit patterns correspond to different values).

Long integers

These represent numbers in an unlimited range, subject to available (virtual) memory only. For the purpose of shift and mask operations, a binary representation is assumed, and negative numbers are represented in a variant of 2’s complement which gives the illusion of an infinite string of sign bits extending to the left.

Booleans (False 0 et True 1)

These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of plain integers, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively.

The rules for integer representation are intended to give the most meaningful interpretation of shift and mask operations involving negative integers and the least surprises when switching between the plain and long integer domains. Any operation, if it yields a result in the plain integer domain, will yield the same result in the long integer domain or when using mixed operands. The switch between domains is transparent to the programmer.

"


» Glossaire du langage python