Thank You!
A book takes many people working together to make it a reality. So, to all the Kickstarter backers that helped me complete this project I wish to express a big Thank You and I hope we can do more great things in the future.
Anthony Storms Akins
Alan Prak
Alessandro
Andy Lee
Bill Stull
Brandon Thompson
Charles Rogers
Clment Labadie
Demian Vonder Kuhlen
Edgar Rodriguez
Gordon
Greg_Vee
Gregory Pfrommer
Gregory R. Kinnicutt
J.T. OGara
Janakan
Jeff
Joe
Joshua Bauder
Marco Randall
Marshall Walker
Neer Patel
Nigel J Allen
Padrao
Perry Yap
R.C. Lewis
Randy Morris
Rowan Knight
Sebastian Lange
Shahid Ali Shah
Shrawan
Stan Spears
Credits & Legal
AUTHOR
Ivelin Demirov
EditorS
Anton Berezin
Beth McMillan
Page design
Jordan Milev
Illustrator
Ivelin Demirov
Proofreader
Beth McMillan
ACKNOWLEDGMENT
I must acknowledge the help of the online Python community, who have toiled in the background for many years to help make Python the exciting programming language it has become
COPYright
2015 Ivelin Demirov
notice of rights
All rights reserved. No part of this book may be reproduced in any form, by any means without the written permission of the publisher or the author.
trademarks
All trademarks are held by their respective owners.
notice of liability
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of the book, neither the author nor the publisher shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it.
Paperback ISBN
ISBN-13: 978-1507727072
ISBN-10: 1507727070
contacts
pythonvisually.com
Contents
About this book
The Problem
People cannot be blamed for thinking programming is hard when trying it out for the first time. Learning to program is like learning a new language.
A number of rules and grammar syntax guidelines exist to follow. It also requires memorizing a bevy of glossary terms for each language, and unless a person works with programming at least 8 hours a day, the person is unlikely to become very familiar with programming quickly; at least, that has been the situation for years until now.
The Methodology
Our approach involves teaching programming concepts via simple illustrations.
The visual approach works because it is one of the most fundamental ways of learning. Everyone as a baby and toddler learns the world around them via sight and sound long before there is comprehension associated with letters and meanings.
Programming works in modules and building blocks. As a person learns a few basic modules and steps, he can then learn to build more complex modules on those first basic units.
Its a building block approach where bigger structures can be coded once the basic modules are mastered. I start with a set of basic building blocks that are easy to learn through illustrations and metaphors.
From there, a user can apply multiple variations and build further. However, the initial set of building blocks becomes a Rosetta stone of sorts, allowing a user to program and build in any situation going forward.
Why Python?
When you embark on your computer science journey at college, youll probably start by learning Python.
So why choose Python over any other programming language?
Its simple:
- Regardless of your operating system, Python is easy to set up.
- Python code uses plain English, making it easy to understand.
- Python will let you run bad code.
Why is this good?
When youre learning youre bound to make mistakes.
Python tells you what the error is after you run the code, helping you to find the problem. - Python is a very powerful tool, but its also easy and fast to learn, which is why most people prefer it.
Installation
There are pre-compiled packages made for easy installation on multiple operating systems such as Windows, Linux, UNIX and Mac OS to name but a few.
If you head over to https://www.python.org/downloads/ you can select the right installation method for your operating system. Most Linux systems come with Python pre-installed.
Version 3 of Python is used in this book.
In Windows, once you have installed Python, select Python IDLE or Python command line/console from the Start menu or screen.
The difference between the IDLE and the console is that the IDLE has a graphical interface, which looks similar to a text editor. In Linux, UNIX, and OS X, you can launch Python emulator from command line by typing Python.
To choose a specific version of Python type PythonX where X is the version number (e.g. Python3 for version 3).
Hello World!
Most of the time that you write Python code, you will be writing the script in the IDLE or any other IDE like Eclipse or rich text editor like Sublime text or Notepad++. However, you can use the Python interpreter to write code interactively as it acts like a UNIX shell,
Even though it is possible to create programs using just the interpreter it is strongly recommended not to do so since it is hard to save the code as a script for further reuse. Rather consider the interpreter as an on the fly testing tool for your coding ideas.
Now lets make the interpreter output Hello World! string on the screen. Lets do it via the interpreter.
Terminal way
Launch the interpreter from command line using Python command as it was described in the previous chapter.
Type the following: print(Hello world!) and hit Enter.
The terminal shall look the following way:
In the code snippet above you can see that the first line starts with >>> .
This symbol indicates the line where you provide dynamic input to the interpreter. Notice, as soon as the result of your first command was printed on the screen the interpreter printed >>> again. Giving instructions to the interpreter is sequential. You give one instruction - you wait till execution finishes, you enter another command and so on.
Note, further on in this book if you spot >>> symbol in a code snippet it shall mean that you are expected to test the code in the interpreter yourself.
On the first line you entered a statement. The statement is nothing else but an instruction for a computer to perform some task. The task could be anything from make_a_coffee to launch_a_rocket . In your case it is a simple print function though.
Functions will be covered further in this book.
Scripting Way
One of the main principles of software engineering is reusability.
Lets make the code that was just tested in the interpreter reusable.
To do so, create a file called hello_world.py and type the following text inside:
Next page