CyberArmy Academy | CyberArmy Services & Support | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Projects

[Library Index]

[View category: Python] [Discuss Article]

Homebrew Python Introduction

Article Rating: Above Average (# of votes: 2)
Author:      Deaf Cow
Submitted:      06-May-2008 18:12:03
 


This Homebrew Python Introduction will guide you through the installation of Python and fix a common error with the latest Python. This guide also features some basic commands.
  1. What is Python?
  2. Why should you learn Python?
  3. How to install and run Python.
  4. Some basic commands and how to use IDLE.
What is Python?
Python is a great programming language that is used in all sorts of software. It is easy to understand and looks a lot like Java and VB. Python is certified as a "Very high-level programming language", which means that it has a high level of abstraction and is very goal-oriented. However, that does not mean it is hard to learn; most commands have a very understandable name that defines their use very well.

Python is an open and community based development model; you're free to modify, erase and change it. Python is used in all sorts of software, and by big names like Youtube, Bittorrent, Yahoo, Google and even NASA!

Why should I learn Python?
Python will expand your knowledge about computers. You'll be able to learn other languages much faster, including Java and VB as they are similar. If you dive right in, you'll be able to create dynamic and useful programs fairly quickly.

How to install Python
First we'll need to download the Python Installer from the Python website (I'm not going to guide you through all of this; it's pretty straightforward. Just install everything as we might use it in further tutorials).

Let's start the real deal now! Programming!

Basic commands and how to use IDLE.
Let's first start up IDLE. Start > Programs > Python > IDLE. You'll see a screen called "Python Shell" now; this is our test screen. It will automatically show us the output of the actions we type.

Let's try out the print function, type:
print "Hai, voide!"
Press enter, and the text will be displayed on the screen automatically! Congratulations, you've made your first program!
Save it (file > save as (with .py extension)) and try to run it.
It will automatically be run in the command prompt and you'll see the output of the code.

The print function does not only let us display characters, it also let's us calculate stuff using the standard programming math operators.
print ((5*5) +  (7 - 2)) / (12 / 2) 
#If we leave out the parentheses we will get a different output
Have you tried to divide 6 by 4? You will see that you'll get a whole number. To change this put this line at the top:
from __future__ import division #If you want to keep the whole number use % instead of /
We've seen that we can print strings and numbers, but we can combine these as well.
print "The multiplication of %d and %d is: %d" % (4,5,4*5) 
#The string has a '%' character in it followed by a d, it says that a 
decimal number should be placed there, which can be found in the brackets.
In the next tutorial we will make a small program which requires user input and learn how to assign data to variables.

You must be logged in to vote on an article

About Us | Privacy Policy | Mission Statement | Help