Python - Comparing Data Types - Learn Python Programming with Code Examples - APPFICIAL

Publicado el: 16 septiembre 2021
en el canal de: Appficial
1,623
9

Numbers are compared arithmetically.

Strings are compared character by character, in the same position of both strings. If two characters are different, then their Unicode value is compared; the character with the smaller Unicode value is considered to be lower.

Lists and tuples are compared via an ordered comparison of every element in the sequence. In order for two lists or tuples to be equal, every element must be equal.

Dictionaries are only compared with == and != operators. In order for two dictionaries to be equal, they must have the same set of keys and same value for each key.

Some common branching errors are using = to check for equality rather than ==. = is the assignment operator in python. Another common mistake is using invalid operators such as not greater than.

You get a TypeError for comparisons that don’t make sense, such comparing 5 to ‘grams.

Note: You can compare int and string with the equality operator ==, but do not compare floating-point values with the equality operator == because of the imprecise representation of floating-point numbers. Comparing 1/3 with 0.3333 will return false. You can use an epsilon value when comparing floating point number, and we will discuss that in a later section.

Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!


En esta página del sitio puede ver el video en línea Python - Comparing Data Types - Learn Python Programming with Code Examples - APPFICIAL de Duración hora minuto segunda en buena calidad , que subió el usuario Appficial 16 septiembre 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,623 veces y le gustó 9 a los espectadores. Disfruta viendo!