• [^] # Re: Question de type

    Posté par . En réponse au journal Rigolons avec l'ascii. Évalué à 0.

    Si il n'y a pas transtypage, il y a au minimum un test de type effectué par l'opérateur.

    Dans https://docs.python.org/2/reference/expressions.html#value-comparisons Il est indiqué :

    • Strings (instances of str or unicode) compare lexicographically using the numeric equivalents (the result of the built-in function ord()) of their characters.

    • When comparing an 8-bit string and a Unicode string, the 8-bit string is converted to Unicode. If the conversion fails, the strings are considered unequal.

    Ce qui est une convention, la valeur renvoyée par ord() étant un retour sans doute de la position dans la table de caractères.

    Le fait que :

    > '1'.__gt__(1)
    NotImplemented
    

    Donne a penser que les types String, Number, etc ...sont bien pris en compte quand il y a comparaison entre deux objets.