Python 3 Essential Training: Compare Values of Python 3


show more Comparing values provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Comparing values

Python also has a complete set of comparison operators. For example, if I say 5 < 6, I'll get True. If I say 6 < 5, I'll get False. Likewise, if I say 5 <= 6, I'll get True, or 5 <= 5, I'll also get True. It also has greater than or equal to, 6 >= 5 or 6 >= 6.

6 is not of course >= 7. And equality is tested with the double equal signs. So 5 == 5 is True. And 5 == 6 is not True. Then it has a not equal operator. So 6 != 7 is True. And 6 != 6 is False. It also has is and is not, and these are for testing id.

So for example, if I have two variables x and y, and we'll assign them values of 5 and 6. So the id(x) is that, and the id(y) is that. So they're not the same. So if I say x is y, I get False. If I say x is not y, I get True. Likewise, if I assign 5 to y, now their ids will be the same.

Id(y) is the same as id(x). Now x is y. For immutables like integers, the ids are always going to be the same if the value is the same. So testing equality and testing...

Comparing values
Video duration: 3m 32s 6h 36m Beginner

Viewers:

Comparing values provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Subjects:
Developer Web
Software:
Python
Author:
please wait ...