An Introduction to Python
Python is an object-orientated programming language often used by ‘beginners’: people who are interested in programming, but get mad at seeing a part of code of languages such as C++, C and others.
Note: This article is an introduction to Python. If you already know the basics it’s spoiled time reading this article.
1. Small history of Python
2. How to get
3. The basics
1. Small History
Because I usually find history of programming languages boring, I will try to keep this part as small as possible. The father of python is the Dutch programmer Guido van Rossum. At this moment (April 2007) version 2.51 is the latest version. If you want to know more about the history you should check it on wikipedia.
2. How to get
Python can be downloaded at: http://www.python.org/. Here you will be able to download the latest version for Windows, Mac and Linux. After downloading, the installer (on windows) will show you the way through to install. For the other two platforms: most people using these are smart enough to install it themselves.
3. The Basics
Over to the real work: Starting to program. After installing you will find in your programs map>python>IDLE (Python Graphical User Interface). Start this.
In this program you can use python commands just to see what they do. I usually ‘test’ my stuff in here. Pretty handy!
Well why don’t you try for yourself? To see a string use ‘print’ (example):
print "hello this is my first python-day"
You will see that under your code ‘hello this is my first python-day’ will pop-up. You just learned your first command! But we are still in this ‘testing-environment’. You probably want to make programs and not only test your code. If you want to make a program go to: file>new window in your IDLE. Now a new window shows up.
Type the same as in the example, but now only in this new window. After that save the file (file>save) as test.py for example. Press F5 and your program will be run in the IDLE, and your text will show up. Easy?
We will go on to variables. Variables are easy to use in long sums, though I will give you an easy example:
a = 5
b = 10
c = a+b
You will see 15 be printed if you execute your program like stated before. Note: after print, I don’t use “c”. This is because I defined c before. In the same way you can use variables for strings. Just check the example:
name = "Ganesh "
friend = "and Sagaro"
both = name + friend
…and yes you will see ‘Ganesh and Sagaro’ pop-up.
The last command you will learn in this introduction is an input command. With raw_input() you will be able to input your own information or store information that you put in into variables. The following example will explain it:
myname = raw_input("Enter your name here. ")
print "hello", myname
In the same way you can store numbers, though you will have to put the command ‘int()‘ (that is for integer) around raw_input() in this way: int(raw_input(“Give me a number that you want to square “)). (try to make that kind of program)
Well, we have come at the end of this introduction to the language Python. Note that this are the very basics of this language and that you will be able to do more when you start progressing. If you are looking for more articles I want you to take a look at the following sites:
– http://www.ibiblio.org/g2swap/byteofpython/files/120/ (Free book)
– Or just take a look at the programming forum.
Filed under: Extras, How-To, Monthly Spl., Techies | 8 Comments