Python Tutorial No.1




This is a Python tutorial made with the absolute beginner in mind.

A brief introduction to Python will serve to give you a basic understanding of the history and what it is, before we move on to lessons.

What is Python?
Taken from

Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days.Many Python programmers report substantial productivity gains and feel the languageencourages the development of higher quality, more maintainable code.

In other words, Python is easy to learn, read, and write, ensuring that you'll be able to understand what you wrote a few months after you wrote it.

A Brief History of Python.

Python was conceived in the late 1980s by Guido van Rossum in the Netherlands as a successor of the ABC programming language, and it soon gathered popularity, especially after it was released under the GPL in version 1.6.1.
Today, some of the largest projects that use Python are the Zope application server, and the original BitTorrent client. It is also extensively used by Google and NASA.

Note: This instructable is being actively edited and improved by it's author(ZN13) and collaborator(Hugo.B) so please be patient and keep visiting, you'll find learning Python a rewarding experience.

ZN13 Hugo.B

Step 1: Download Python

To program in Python you'll need to download the Python libraries, and
the Integrated DeveLopment Environment, IDLE

As of 16/6/07, the release is version 2.5.1
Python Download here.

We'll assume that you are using windows here, but if you're using any
Linux-based OS, it'll likely already have it installed.
To find out, open console/konsole/terminal(varies with distro), and type
python. If it is installed, the Python command-line will open up.

After you have installed it, go Start>All Programs>Python>IDLE and we'll get started!

Step 2: Program Output, Print Statement, and "Hello World"

Here we'll teach you one of the first things almost any programmer learns: how to print "hello world". It is the programmer's perennial first example. Note, print doesn't mean print as in ink and paper, it merely means display, or output.
Anyway, here goes:
At the primary prompt(>>>) enter:

>>>print "Hello World"

And you'll receive the output of:

Hello World

N.B. You need the (" ") characters to indicate to Python that you want it printed, otherwise
you'll receive this:

>>> print hello worldSyntaxError: invalid syntax

with "world" would be highlighted in red, to show where you went wrong.

Step 3: Variables

A variable(to the best of my knowledge) is a link to another piece of data:
I'll demonstrate:

Type this into IDLE:

>>> myvar = "Hello World!">>> &apos&apos&aposprint&apos&apos&apos myvarHello World!

myvar is the variable in this example, but variables can also be numbers.
That is a short example of how a variable works.

Making things a little more complex now, an introduction to the string format operator:
The percent sign: "%" can be use it to replace text/data in a string:

>>> print "%s is number %d! " % ("Python", 1)Python is number 1!

"%s" means to substitute a string while "%d" indicates an integer should be substituted.
Another popular one is "%f" for floating point numbers.

Step 4: Program Input and the Raw_input() Function

The easiest way to obtain user input from the command line is with the
It reads from standard input and assigns the string value to the variable you designate.
For example, this is how it is used:

name = raw_input("Enter your name here: ")age = raw_input("Enter your age here: ")print "Your name is:", nameprint "And you are", age

When the Python interpreter reads the first line, it'll print the content in parenthesis(Enter your name here:), and when you input your name, it'll go on to the next line, do the same, but when it come across the "print" statement it prints the content in parenthesis, and comes across
"name" which is a variable, basically acting as a link to the content you entered earlier, with the following result:

>>>Enter your name here: Hugo.BEnter your age here: 16Your name is: Hugo.BAnd you are 16

At this stage, it'd be a good idea to introduce to the method of leaving comments.
As with most scripting and Unix-shell languages, the hash or pound (#) sign signals that a comment begins from the # and continues until the end of the line.
Note, in IDLE, whenever you type the # sign, it and all following text on that line turns red.

#Warning!!! This will put CPU usage up to 100% !!!counter = 0while counter < 1000000:    counter += 1    print counter

Step 5: Ongoing...

Temporary placeholder:
Awaiting new content, please be patient.




    • Pets Challenge

      Pets Challenge
    • Sensors Contest

      Sensors Contest
    • Classroom Science Contest

      Classroom Science Contest

    16 Discussions


    7 years ago on Step 4

    **Correction: as of Python 3.x "raw_input" is no longer working. For string input use "input()" or for a number use "eval(input())"

    1 reply
    kinglarry IIjf78

    Reply 10 months ago

    for integers use float(input()) or int(input())

    kinglarry II

    10 months ago on Step 2

    in python 3.x.x , always do print ('hello world')

    dungeon runner

    8 years ago on Step 3

    The way I was taught about variables, the best way to imagine it is by analogy. Imagine having a room full of little strips of paper, each one with a single number, bit of text, etc. written of it. If you want to find the strip with the information you want, it would be pretty hard, because it's impossible to know which contains which. To solve this problem, you put each strip of paper in a cardboard box with a name printed on the front. You could make a strip with the number of car Ford has made in the last year written on it, put it in a box labeled "number of cars", and then if you wanted to recall it, go to the box with that label and look inside.

    The strips of paper are places in the memory of the computer. Variables are given names, so that you can use the name as shorthand for whatever the value of the variable is; you use the same name regardless of what the current value is, so we call them "variables" (because they vary


    wizerd 745

    9 years ago on Introduction

    Can't wait till you can continue work on this!
    So far so good


    10 years ago on Introduction

    hmm...good,I finally get how it works,i learned a few functions


    Reply 10 years ago on Introduction

    I thought it was kool, just knid of looks like it was copied from another site....


    11 years ago on Introduction

    Its just a tutorial about Python...Python's cool and he explained what this tut was...


    12 years ago on Introduction

    Please be patient, this instructable is being actively upgraded, continue visiting, and submit any bugs/errors/mistakes to ZN13 or I. This is intended to be a comprehensive starter's guide to Python. Thanks for visiting. H.B.


    12 years ago on Introduction

    cool, I did not know about the input() command. But it allows you to run arbitrary code... not what you wanted to do just to read a number from the user.
    for example, if you had the os module already loaded with import os...
    >>> input("num:")num:os.system("echo fubar")fubar0

    you can run an arbitrary shell command in the os.

    12 years ago on Introduction

    maybe you can first tell us what it is and then start the tutorial

    1 reply

    Reply 12 years ago on Introduction

    Stolen from Wikipedia "Python is a high-level programming language first released by Guido van Rossum in 1991. Python is designed around a philosophy which emphasizes the importance of programmer effort over computer effort, and it prioritizes readability over speed or expressiveness. Python is often characterized as minimalist, although this only applies to the core language's syntax and semantics; the standard library provides the language with a large number of additional libraries and extensions."