Python
  Home arrow Python arrow Page 2 - Introduction to Python Programming
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · Hey thanks for dropping by for this exciting episode of...Pigs...in...Space! Well...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway