Python: A Gentle Introduction to Programming
Where would hardware be without software? Besides a very expensive paper weight, hardware would be absolutely useless without software to operate it. Hardware needs software to wield and control its various functions, like a puppeteer cleverly promenading a marionette on a stage. A puppet without the alacrity of skilled fingers becomes sadly defunct, as does hardware without the guidance of software. Software abstractly instructs hardware on what to do; hardware provides a tangible means to do it. When you learn to speak the language of the machine�software�you gain an extraordinary amount of power and clout over your computer; you become master and commander of your PC, bending it to your every desire.
Ok, so you want to tap into this digital power; how does one go about doing it? First things first, so you'll need to choose a programming language to code your software in. A programming language is nothing more than a human readable form of instructions for your computer, which, for your computer's benefit, eventually gets converted into pure binary code for your machine to digest and execute. When you abstract the only language that your computer can comprehend (binary instructions) into a human readable syntax, it becomes a lot easier to write software. Believe me. You don't want to code an entire operating system in pure binary unless you want to take permanent leave of your faculties.
Programming is a complex task. When you're just starting out, it's best to learn the absolute basics first, lest you want to frustrate yourself beyond belief. Let's start out with my favorite language: Python. Python is an awesome general purpose programming language that comes with a �batteries-include� library of coding modules. If you're on Linux, pull up a shell and type in �python� to get into an interactive prompt. If you're on a Windows box, you can download a Python installation package from activestate.com; once installed, upon up cmd.exe (type �cmd� in the run box) and type in �python�.
You should see something like this at the prompt:
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You are now engaged with a Python Interactive session. This environment is perfect for beginners because they can start coding right away, learning the ropes as they go along.
Type the below command and press enter:
>>> print 'hello world!'
Did you see that? The session printed out �hello world!� What just happened is quite interesting. The �print� command takes what you give it and prints it out to the shell. The text, �hello world!' is called a �string�, which is just a collection of characters. You'll be using the �print� statement a lot, as you'll want to view your program's output from time to time.
This is an opportune time to discuss �variables�. Think of a variable as a cubby hole of sorts; you can put stuff in, and you can retrieve your stuff later. Variables have names that you can refer to when you need them. Common variable names include:
num_of_clients
SizeOfDisplay
customerName
Notice that spaces cannot be used in variable names.
Try this at the shell:
>>> my_name = �Mike'
You've just created a variable, and you assigned the string �Mike' to it. You can now refer to your new fangled variable via its name.
>>> print my_name
The above should output �Mike� at the shell.
Let's jazz it up a bit:
>>> print 'Hello my name is', my_name
I just combined the string �Hello my name is� with the contents of the �my_name� variable. The print statement outputs �Hello my name is Mike�.
Why don't we give Mike an age? Define another variable called �age�.
>>> age = 26
Now we can get really fancy:
>>> print my_name, 'is', age, 'years old.'
�Mike is 26 years old� is output to the shell.
You've just witnessed the absolute basics of programming. You can't do anything really earth shattering yet, but, with practice and disciple, you'll be able to do some really neat stuff. Consult Google if you would like to learn more about Python and programming in general. Google knows all.
More On Linux
-SuSe Linux
-Partition Your Hard Drive For Linux
-Make A Start Up Disk For Linux
-Touring the Linux File System
-Emacs - A User's Best Friend
Back To Tips Homepage
Popular Articles:
How To Build A PC | Different Types of Keyboards | Help with Hard Drive Installation | Computer Networking Basics | Introduction of Motherboard Functions | Computer CPU Processor Speed | Upgrade from Windows 95 to Windows 98 | Computer Monitor Troubleshoot | Partition Hard Drive | Installing New CPU Processor | Types of Network Cables |