In my article on learning the fundamentals of Windows PowerShell, I mentioned that I am in the progress of learning Python. When learning a new programming language, one of the first things you’ll do, besides writing Hello World, is learning about the operators, variables, datatypes and so on and so forth. So naturally, when I started with Python, I did the same!
Installing Python and choosing a text editor
Before I get into numbers and operators, I figured it might be a good idea to quickly go over how you can start using Python yourself.
First, visit the official Python website and download the latest 3.X.X version of Python. The installation is very straightforward, but there is one thing you must do when you’re going through the installation process. That is checking the “Add Python 3.X.X to PATH” checkbox. Adding Python to PATH allows PowerShell as well as IDE’s like PyCharm to access Python and identify that it is installed on your computer.
After installation, you also need a text editor to write your code in. My editor of choice is Sublime Text, which is free to use and very powerful and versatile. I have used and recommended it for HTML5 and CSS as well.
To verify that Python was installed correctly, open PowerShell. In PowerShell, type Python and hit enter. If it gives you a message starting with “Python 3.X.X”, installation was successful. If not, something went wrong and you might have to try again.
After entering Python as a command, you also have instant access to the Python Interpreter, which means you can run Python code in PowerShell. Try using the print command and enter Hello World!
print("Hello World!")
Integers and Floats
There are a few datatypes in Python specifically for numbers. The most important ones are Integers and Floats. Ints are whole numbers (5, 205, 61087, -10). Floats are decimal point numbers (2.5, 6937.295 and even 1.0). If you want to know more about all the other datatypes, the best resource is Python’s official documentation.
Numbers and operators
Now that we’ve got all that stuff out of the way, let’s get into the operators. The operators in Python are very similar to those in other programming languages. You have a set of basic operators and some more advanced mathematical operators. Since we are just starting out, I will be covering only the basic operators in this post.
Operator order of precedence
A last important thing to note is the order of precedence when combining multiple operators. When combining multiple operators, certain operators take precedence over another. If you don’t know this order, a calculation might yield a different result then you expected. I recommend you check this page that has a full table for the order of precedence, as well as some examples.
Wrapping up
So that was a quick overview of using numbers and operators within Python. Hopefully you’ll be able to try some calculations within PowerShell and even within some basic Python programs. Don’t forget to use the Python documentation if you need a refresher on the operators and datatypes!
Let me know if this was helpful or if you would like to see more of these types or articles in the future and as always, if you have questions or concerns, feel free to comment below and make sure to share the article if you liked it!