Python
  Home arrow Python arrow Page 2 - Introduction to Python Programming
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Introduction to Python Programming
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2007-11-12


    Table of Contents:
  • Introduction to Python Programming
  • No one expects the Spanish Inquisition!
  • Working with Numbers
  • Python Mathematical Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Introduction to Python Programming - No one expects the Spanish Inquisition!
    ( Page 2 of 4 )

    As is the case with all computer programming tutorials, the first thing you learn to do is print some text to the screen. Normally it is a stupid “Hello World” program, but you are far too cool for that. Besides, the Spanish Inquisition is seeking us out, and the last thing we want to do is send a big old greeting out to the world. Here is how you print text to a monitor:


    #!/usr/local/bin/python #this line must be included in every program


    print “We are the Spanish Inquisition!”

    The above code will print this to your monitor:

      We are the Spanish Inquisition!

    To view the program in Python, save the file as firstprogram.py and open it in Python (type python firstprogram.py). Note that you must make sure that you can view and edit file extensions in your operating system, otherwise Notepad will change your file to a .txt and it will not work. To remedy this, simply turn on view file extensions, and rename the file with a .py extension.

    You will note several things about the preceding code. First, the first line: #!/usr/local/bin/python tells the computer where Python is located. If you change where your python directory is located, you will have to change it in your code as well. This line must appear in all of your Python code.

    Next, the line print “We are the Spanish Inquisition!” tells the computer to literally print the sentence in quotations to the user's monitor. Pretty simple right?

    If we wanted to print more than one line of code we could do this:


    #!/usr/local/bin/python #this line must be included in every program


    print “We are the Spanish Inquisition!”

    print “We have two weapons!”

    print “One...fear!”

    print “Two...obfuscation!”

    print “And vigilance!”

    print “Oh shucks did I say two weapons? I meant three.”

    print “Why don't I step outside, then we will re-enter and begin again.”

    This would result in the printout:

      We are the Spanish Inquisition!

      We have two weapons!

      One...fear!

      Two...obfuscation!

      And vigilance!

      Oh shucks did I say two weapons? I meant three.

      Why don't I step outside, then we will re-enter and begin again.

    A Brief Word On Terminology

    In the above code sample we worked with the print command. This was followed by quotation marks and some text, which is referred to as an argument. The text in the argument is referred to as a string. The combination of the command and the argument is known as a statement. So the line: print “We are the Spanish Inquisition!” is an example of a statement.



     
     
    >>> More Python Articles          >>> More By James Payne
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT