Introduction to Python #001
Starting your journey to learning Python.
CodeBrew! For everyone on this email list - thank you for staying on and bearing with me. There were some backend things that took much longer than expected, and here we are 3 weeks later than expected. I’m sorry, but we are here to stay and will be pumping out WEEKLY content!
Overview of this Course
Welcome to Introduction to Python! I am so glad that you are here on this journey to learn Python programming. It’s going to be a great 4 months and have a ton of great things planned for you along the way!
In case you forgot, we will be doing these languages in 4-month segments and then at the end, you will have the ability to continue to learn and harness your skills even further, or continue on in the newsletter with another language - completely up to you! So this Python section of the newsletter will continue until February 10th, where we will then transition into
If you have any questions, send them our way to email@example.com and we will have answers for you shortly. Or follow me on Twitter and shoot me a DM!
Introduction to Python Course #001
What is Python?
Python is an open-source programming language created by Dutch programmer Guido van Rossum and named after the British sketch comedy group, Monty Python’s Flying Circus. One of van Rossum’s key insights was that programmers spend more time reading code than writing it, so he created an easy-to-read language. Python is one of the most popular and easiest to learn programming languages in the world. It runs on all the major operating systems and computers and is used in everything from building web servers to creating desktop applications. Because of its popularity, there is a large demand for Python programmers.
In order to follow the examples in this book, you need to have Python 3 (version 3 of Python) installed. You can download Python for Windows and OS X at http://python.org/downloads. If you are on Ubuntu, Python 3 comes installed by default. Make sure you download Python 3, not Python 2. Some of the examples in this book will not work if you are using Python 2. Python is available for both 32-bit and 64-bit computers. If you have a new computer, purchased after 2007, it is most likely a 64-bit computer. If you aren’t sure if your computer is 32-bit or 64-bit, an internet search should help you figure it out. If you are on Windows or a Mac, download the 64- or 32-bit version of Python, open the file and follow the instructions. If you are a more visual learner check out our tutorial here on installing Python on a Mac.
The Interactive Shell
Python comes with a program called IDLE (short for an interactive development environment ); it is also the last name of Eric Idle, one of the members of Monty Python’s Flying Circus. IDLE is where you will be typing your Python code. Once you’ve downloaded Python, search for IDLE in Explorer (PC), Finder (Mac), or Nautilus (Ubuntu). I recommend creating a desktop shortcut to make it easy to find.
Click on the IDLE icon, and a program with the following lines will open up (although this could change so don’t worry if the message is absent or different) and you’ll get:
This program is called the interactive shell. You can type Python code directly into the interactive shell and the shell prints the results. At the prompt (>>>) type:
and press enter.
IDLE might reject code that is copied just an FYI. If you copy and paste code and get an unexplainable error message, try typing the code directly into the window. You must type the code exactly as it is written in the example, including quotation marks, parentheses, and any other punctuation.
The interactive shell will respond by printing Hello, World!
In the programming world, when you teach someone a new programming language, it is a tradition that the first program you teach them is how to print Hello, World! So, congratulations! You just wrote your first program.
The interactive shell is useful for quick computations, testing small bits of code, and writing short programs you don’t plan on using again. You can also use IDLE to save a program for reuse. Start the IDLE application, click “File” (in the menu bar on the top left of the IDLE editor) then select “New File.” This will open up a text editor, which usually has a blank white background. You can write your code in this text editor, then save it to run later. When you run your code, the output of the code you wrote will appear in the interactive shell. You need to save your changes while editing code before running it again. Type the Hello World! program into the text editor:
Go to “File” again and select “Save As.” Name your file “hello_world.py” and save it. Python files have to end with .py. Once you’ve saved your file, click “Run” (again, in the menu bar in the top left corner of the IDLE editor) and select “ Run Module .” Alternatively, you can press the F5 key command, the equivalent of selecting “Run Module” from the menu bar. Hello World! will print in the interactive shell, as if you had typed this line of code. However, in this case, since you saved your program, you can run it as many times as you like. The program you created is simply a file with a .py extension, located on your computer wherever you saved it. The name I chose for the file—“hello_world.py”—is completely arbitrary, you can name the file anything. Like this example, writing programs in Python simply involves typing text into files and running them using the interactive shell. Easy, right?
We’ll soon start diving into some more in-depth programming next week, and wanted to provide you with some terms that will be very common throughout the next week.
programming: Writing instructions for a computer to execute.
code: The instructions programmers write for a computer to execute.
low-level programming language: A programming language closer to being written in binary (0s and 1s) than a high-level programming language.
assembly language: A type of difficult to read programming language.
high-level programming language: A programming language that reads more like English than a low-level programming language.
Python: The easy to read, the open-source programming language you will learn to use in this newsletter.
Challenge - Print something else other than Hello World.
That is where we are going to wrap up this week. This week is shorter than most will be, but the introduction is always the hardest and trickest. If you have any problems getting Python installed or IDLE running, let me know on Twitter or via email.
Try messing around with IDLE and see what you can do on your own! Next week we will be covering variables, comments, and loops! This is when you will start to see your programming do some cool things!
We hope you enjoyed the first newsletter, and there will be many, many more to come. If you enjoyed the newsletter, please go ahead and share or subscribe if you haven’t yet it would be very appreciated!
Share Code Brew here!
Questions? If you have questions or comments, reply to 📥 firstname.lastname@example.org📥 or Twitter (HERE) and I will get back to you!