NSI · PREMIÈRELes variableset les typesint · float · str · bool4 JUIN 1996 · ARIANE 5Une valeur trop grandeflottant sur 64 bitsconversionentier signé sur 16 bitsau plus 32 767débordementle calculateur s'arrêteEn Python, un int n'a pas de taille limite>>> 2 ** 1001267650600228229401496703205376LA VARIABLEUn nom, une valeurx = 3x3type : intx = "NSI"x"NSI"type : strL'affectation associe un nom à une valeur.C'est la valeur qui porte le type.LES TYPES DE BASEQuatre types en Pythonintentier42floatflottant3.14strchaîne de caractères"NSI"boolbooléenTrue, FalseIDENTIFIER UN TYPELa fonction type()>>> type(42)<class 'int'>>>> type(42.0)<class 'float'>>>> type("42")<class 'str'>>>> type(True)<class 'bool'>Avec un point : un flottant.Entre guillemets : une chaîne.CONVERTIRChanger de typeint("42")42float("2.5")2.5str(7)'7'int(3.9)3décimales perduesint("3.5")ValueErrorConvertir, si la valeur s'y prête.UNE VALEUR APPROCHÉELe flottant>>> 0.1 + 0.20.30000000000000004>>> 0.1 + 0.2 == 0.3FalseEN BASE 2, 1/10 S'ÉCRIT SANS FIN0.0001100110011…Sur un nombre fini de bits, il est arrondi.Ne pas tester l'égalitéde deux flottants.À RETENIRVariables et typesLa variableun nom associé à une valeur par affectationint, float, str, boolidentifiés par type()Convertirint(), float(), str(), si la valeur s'y prêteLe flottantune valeur approchéeJLjeromelabbe.frFiches de connaissance · NSI, 1reJL