Friday, 20 May 2016

Python Programming



The First Steps
 
The absolute first step you need to take before you can begin programming in Python is to download
and install Python version 3.1. Navigate to www.python.org/download and choose the newest version
of Python. You will be taken to a page with instructions on how to download the appropriate version for
your computer. For instance, if you are running Windows, it may say Windows x86 MSI Installer (3.0).
Programs are written in a form called source code . Source code contains the instructions
that the language follows, and when the source code is read and processed, the
instructions that you ’ ve put in there become the actions that the computer takes.
Just as authors and editors have specialized tools for writing for magazines, books, or online
publications, programmers also need specialized tools. As a starting Python programmer, the right tool
for the job is the Python IDLE GUI (graphical user interface).
Once the download is finished, double - click it to run the program. Your best bet is to accept the default
prompts Python offers you. This process may take a few minutes, depending on your system.
After setup is complete, you will want to test to make sure it is installed properly. Click the Windows
Start menu and go to All Programs. You will see Python 3.0 in the menu. Choose IDLE (Python GUI) and
wait for the program to load.



Part I: Dipping Your Toe into Python
 
Once IDLE launches, type in “ Test, test, testing ” and press the Enter key. If Python is running correctly, it
should return the value
‘Test, test, testing’
in blue letters and with single quotes (I ’ ll get more into this soon). Congratulations — you have
successfully installed Python and are well on your way to becoming a programming guru.



Installing Python 3.1 on Non - Windows Systems
 
If you are the proud owner of a Mac and are running Mac OS X, you are in luck; it comes with Python
installed. Unfortunately, it may not be the most up - to - date version. For security and compatibility
purposes, I would suggest logging on to www.python.org/download/mac . Check to see that your Mac
OS X version is the right version for the Python you are installing.
If you have a Linux computer, you may also already have Python installed, but again, it may be an
earlier version. I would once more suggest you go to the Python website to find the latest version (and of
course, the one appropriate to your system). The website www.python.org/download should have
instructions on how to download the right version for your computer.



Using the Python Shell
 
Before starting to write programs, you ’ ll need to learn how to experiment with the Python shell. For
now, you can think of the Python shell as a way to peer within running Python code. It places you inside
of a running instance of Python, into which you can feed programming code; at the same time, Python
will do what you have asked it to do and will show you a little bit about how it responds to its
environment. Because running programs often have a context — things that you as the programmer have
tailored to your needs — it is an advantage to have the shell because it lets you experiment with the
context you have created.
Now that you have installed Python version 3.1, you can begin to experiment with the shell ’ s basic
behavior. For starters, type in some text:
> > > ”Hello World. You will never see this.”
Note that typing the previous sentence into the shell didn ’ t actually do anything; nothing was changed
in the Python environment. Instead, the sentence was evaluated by Python, to determine what, if
anything, you wanted Python to do. In this case, you merely wanted it to read the text.
Although Python didn ’ t technically do anything with your words, it did give some indication that it read
them. Python indicated this by displaying the text you entered (known as a string ) in quotes. A string is a
data type, and each data type is displayed differently by Python. As you progress through this book, you
will see the different ways Python displays each one.




No comments:

Post a Comment

Popular Posts