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

Pubblicato il: 16 settembre 2021
sul canale di: 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!


In questa pagina del sito puoi guardare il video online Python - Comparing Data Types - Learn Python Programming with Code Examples - APPFICIAL della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Appficial 16 settembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,623 volte e gli è piaciuto 9 spettatori. Buona visione!