Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this chapter, as we look at operators in Python, we are going to be using the Python Shell which is called Idle in a graphical environment, or in a text environment, it's simply the Python Interpreter, run from the command line. Python has all of the standard arithmetic operators. For example, if you say 5 + 5, you get 10. If say 5 * 5, you get 25. If you say 5 - 3, you get 2, and if you say 5 / 3, you get this 1.666.
Python also has some thing that they call floor division, which is simply integer division. If I say 5 with two slashes divide by three then I get 1, which, of course, has a remainder as well. So if I say 5 with a percent sign from modulo and a 3, then I get the remainder. Python also has a built-in function called divmod that gives the two results together. So if we say Divmod(5, 3), then you get both of those results together as a tuple.
Finally, Python has increment and decrement operators, and they are not quite the same as you see in some other scripting languages. If I say num = 5 and I say num += 1, then look at the value of num; we get 6. If I Say, num -= 1 and we look at the value of num, then we get 5. There is also a multiplication and division form of these. So If I say num *= 5, I get 25.
If I say num floor division equals 5, then I get the integer 5. Of course if I say num *= 5 again and then num with one slash /=5, then we get the floating point version 5.0. So those were the basic arithmetic operators that are available in Python. It has all the standard ones, and a couple that it's implemented in its own interesting way.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101765 Viewers
61 Video lessons · 88526 Viewers
71 Video lessons · 72334 Viewers
56 Video lessons · 104054 Viewers
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.
Your file was successfully uploaded.