Welcome to my very first blog post and the start of a multi-part series where we (Yes, you and I!) will be learning how to program in Python! For the entire series, I'll be working my way through Python for DevOps: Learn Ruthlessly Effective Automation by Noah Gift, Kennedy Behrman,Alfredo Deza, and Girg Gheorgiu. The goal is to read through the book and create some fun programs based on what I learn. I don't want this to be a summarization of the book, so you'll still have to read it yourself if you want to know everything that's in it!
Before we can start writing code, we need to install Python. That way, we can run the code we write! You'll want to go to Python.org/downloads to install the latest version of Python for your operating system. The current version at the time of this post is version 3.8.2. I'm on a Windows machine, so I'll be choosing the Windows 64-bit installer. I'm choosing the installer's express option and checking the option to add Python to my PATH system variable. If you don't want what's included by default, or want to include extra tools, you can customize the install.
Once you've finished installing Python, you can validate the install by running the command python --version
in the terminal. I'll be using PowerShell to access the python shell in all my examples.
TL;DR - Use an IDE for an awesome coding experience! Long story short I use Microsoft's VS Code for all my coding shenanigans.
Ok, technically you don't need anything else. You can start writing and executing code by entering the python shell in your favorite terminal. The command is Python
and you'll be able to write your code, hit enter, and it executes. You could also use a basic text editor like Notepad for writing python scripts. All you need to do is save the file with a .py extension and point python to the file. For example, if I wrote a script and saved it as Script.py, I would need to run the following command python Script.py
assuming you are in the same directory.
However, most people use an integrated development environment. This allows you to have access to features like debugging tools, code highlighting, and IntelliSense! I use VS Code but there are plenty of other options out there! I'll also be installing the Python extension for VS Code. This is what gives me all the added benefits over something like Notepad! You can see in the picture it also integrates things like PowerShell directly in the application. This way I don't need to switch between VS Code and the terminal to run all of my python scripts!
Note: I'm using a custom theme. Check it out here! Cyberpunk 2077 anyone?