1.1. The First Step
Have you ever heard of Monty Python’s Flying Circus? It was an old British TV show. Let’s say Hi to the Pythons.
Listing 1. hello python/main.py
print(“Hello Python!”)
It is only one line, but this is a complete Python program. We will learn in this book how to write a program like this and run it on your computer. Without specifying how exactly for now, if we run this program on the terminal, then we get the following output:
Hello Python!
In this book, we will work on slightly more complicated programs. But, first things first. What does this simple program mean? What does it do? How does it work?
Python is a procedural, or imperative, programming language. It supports the object oriented and functional programming styles, among others, but ultimately it is imperative (as in “giving commands”). This means that a Python program consists of a series of “statements”. A statement is an instruction to the computer as to what needs to be done. In the “imperative programming world”, you will need to tell the computer what should be done and how they should be done, step by step, using the statements. That is programming.
This Hello Python program includes one statement, print(“Hello Python!”), print is a “function”. (Note the pair of parentheses following the function name.) In particular, it is a “builtin. function”, meaning that this function is defined in the language itself (and directly built into the “language interpreter”). Programmers can also define their own custom functions in their programs. We will discuss what exactly a function is and how we can create our own functions, in more detail, later in the book.
In this sample code, we “call” the builtin print function with a string “argument”, that is, “Hello Python!”. (Note the pair of double quotes.) The job of this function is to print, to the terminal, the string, or text, passed in to it as an argument. (An argument is what is between the pair of parentheses.) And, that was what it did when we ran the program above.
The argument “Hello Python!” is an “object” of the string type. In Python, everything that we deal with is an object. An object has an “identity”, and each object has a “type” and a “value”. More on this later.
If you are new to programming, and if it all sounds gibberish to you, no worries. We will go over these concepts throughout this book. As indicated, we will do repetition, repetition, and repetition. You do not have to understand everything on your first encounter. At the end of the day, what we call knowledge mostly boils down to “familiarity”.
1.2. The Project
This book takes an interesting, and rather unusual and unique, approach in teaching the basics of programming, in Python.
We will work on one main software project in this book. And, we will mostly focus on the language features and the programming techniques so far as they are useful, or relevant, to the project. On the one hand, this means that you may, or may not, be able to get the complete and comprehensive view of the programming in Python. On the other hand, the real advantage of this approach is that you will get to do the whole software project without being distracted, or overwhelmed, by the nitty gritty details of the entire programming language. The benefits of doing this way will be enormous, especially for the beginning programmers.
Over time, with more training and practice, you will gradually get more exposure to various different aspects of Python programming. But, for now, let’s focus. After completing the project, you will get a sense of accomplishment. You will have learned how to really program in Python, from start to end. That will be a huge accomplishment.
The main project that we will work on in this book is the children’s game of rock paper scissors. We will create a computer program that lets a user play rock paper scissors by themselves (e.g., without requiring a game partner).
Rock Paper Scissors is one of the most popular games. But in case you need a refresher, here’s a Wikipedia page: Rock paper scissors. The particular project that we work on is somewhat secondary. Our focus in this book is learning Python programming. It will be still helpful, however, if you play a few games before we start working on the project so that you are fully familiar with the problem that we are going to tackle. In any real-world programming problems, in general, a lack of domain knowledge can make your job harder as a programmer.
The computer is just a tool. It is you who will have to solve the problems.
Leave a Reply
You must be logged in to post a comment.