Viewers: in countries Watching now:
Due to its power, simplicity, and complete object model, Python has become the scripting language of choice for many large organizations, including Google, Yahoo, and IBM. In Python 3 Essential Training, Bill Weinman demonstrates how to use Python 3 to create well-designed scripts and maintain existing projects. This course covers the basics of the language syntax and usage, as well as advanced features such as objects, generators, and exceptions. Example projects include a normalized database interface and a complete working CRUD application. Exercise files accompany the course.
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 id is almost the same thing, but for immutables, like for example, if I have a list, I say x, y = a list with 5 and another list with 5, now they have different ids, id(x) is that and id(y), you can see that they have two different ids now, even know their values are the same.
So if I test x = y, it's True, but if I test x is y, it is now not True, because they have different ids. They're actually different objects. So those are the comparison operators in Python. You can compare values, and you can also compare ids with is and is not. So when would I want to compare ids? Because Python is fundamental an object-oriented language, everything in Python is an object. And because Python, of course, supports polymorphism there's going to be times when you're going to be using objects.
You may need to know is this exactly the same object as this other object over there? Which object is it that I'm dealing with? And you can't know which is by testing value. So this is a time when you might want to use is and is not to test for the identity of the object rather than just testing the value of the object. So those are Python's comparison operators. Of course, you can compare value, as well as comparing identity.
Find answers to the most frequently asked questions about Python 3 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.