Getting started with a programming language can be tricky, knowing where to start and what to use and how to actually begin coding. This is where The Python Manual comes in.Regardless of whether you’re a student, computer enthusiast or just curious as to how programming works, our tutorials will help you discover how Python works and how it can be used to interact with you and other users. What’s more, you’ll learn how to think like a computer programmer. 100% Unofficial.
Python & C++
Say Hello to Python
Why Python? • There are many different programming languages available for the modern computer, and some still available for older 8 and 16-bit computers too. Some of these languages are designed for scientific work, others for mobile platforms and such. So why choose Python out of all the rest?
Equipment You Will Need • You can learn Python with very little hardware or initial financial investment. You don’t need an incredibly powerful computer and any software that’s required is freely available.
Getting to Know Python • Python is the greatest computer programming language ever created. It enables you to fully harness the power of a computer, in a language that’s clean and easy to understand.
How to Set Up Python in Windows • Windows users can easily install the latest version of Python via the main Python Downloads page. Whilst most seasoned Python developers may shun Windows as the platform of choice for building their code, it’s still an ideal starting point for beginners.
How to Set Up Python on a Mac • If you’re running an Apple Mac, then setting up Python is incredibly easy. In fact a version of Python is already installed. However, you should make sure you’re running the latest version.
How to Set Up Python in Linux • Python version 2.x is already installed in most Linux distributions but as we’re going to be using Python 3.x, there’s a little work we need to do first to get hold of it. Thankfully, it’s not too difficult.
Getting Started with Python
Starting Python for the First Time • We’re going to be using the Raspberry Pi as our Python 3 hardware platform. The latest version of Raspbian comes preinstalled with Python 3, version 3.4.2 to be exact, so as long as you have a version 3 Shell, all our code will work.
Your First Code • Essentially, you’ve already written your first piece of code with the ‘print(“Hello everyone!”)’ function from the previous tutorial. However, let’s expand that and look at entering your code and playing around with some other Python examples.
Saving and Executing Your Code • Whilst working in the IDLE Shell is perfectly fine for small code snippets, it’s not designed for entering longer program listings. In this section you’re going to be introduced to the IDLE Editor, where you will be working from now on.
Executing Code from the Command Line • Although we’re working from the GUI IDLE throughout this book, it’s worth taking a look at Python’s command line handling. We already know there’s a command line version of Python but it’s also used to execute code.
Numbers and Expressions • We’ve seen some basic mathematical expressions with Python, simple addition and the like. Let’s expand on that now and see just how powerful Python is as a calculator. You can work within the IDLE Shell or in the Editor, whichever you like.
Using Comments • When writing your code, the flow of it, what each variable does, how the overall program will operate and so on is all inside your head. Another programmer could follow the code line by line but over time, it can become difficult to read.
Working with Variables • We’ve seen some examples of variables in our Python code already but it’s always worth going through the way they operate and how Python creates and assigns certain values to a...