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

Published: 16 September 2021
on channel: 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!


On this page of the site you can watch the video online Python - Comparing Data Types - Learn Python Programming with Code Examples - APPFICIAL with a duration of hours minute second in good quality, which was uploaded by the user Appficial 16 September 2021, share the link with friends and acquaintances, this video has already been watched 1,623 times on youtube and it was liked by 9 viewers. Enjoy your viewing!