Python
  Home arrow Python arrow Page 2 - Python The Other Scripting Language That Starts With
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? 
Google.com  
PYTHON

Python The Other Scripting Language That Starts With
By: Evelyn Mitchell
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2002-12-24


    Table of Contents:
  • Python The Other Scripting Language That Starts With
  • Hello World!
  • Python and Java
  • What is Python Bad For?

  • 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


    Python The Other Scripting Language That Starts With - Hello World!
    ( Page 2 of 4 )

    Let's jump right in with the unavoidable and always instructive Hello World example, as a springboard into the discussion:

    #!/usr/bin/env python
    print "Hello World"


    produces the result:

    Hello World

    For the sake of comparison, here's the same program in Perl:

    #!/usr/bin/perl
    print "Hello World\n";


    You probably noticed a couple of things about the Python code right away. Consider the command:

    #!/usr/bin/env python

    Portability is one of Python's strong points. Using this #! line rather than the actual location of python on your system allows you to move this code, without modification, to any system that has /usr/bin/env (the equivalent #! line for Perl points directly at the Perl binary).The result is that you can run Python code on more platforms than Java. You can even run Python code within a Java Virtual Machine, using JPython.

    Plus, because Python is an open-source language, it is not subject to the same sort of OS-specific tweaking that Java is known for. (Actually, there are some "OS-specific" extensions to Python -- and not just for Microsoft operating systems. There are SGI-specific sound libraries, for example. These extensions notwithstanding, it is still quite easy to write OS-agnostic programs under Python.)

    Python is a scripting language, so you don't have to define constants or variables before you use them. This can speed code creation when you're trying out alternative solutions to a problem for a prototype.

    What's more, as the Hello World example illustrates, Python doesn't use a lot of punctuation. In particular, Python doesn't use the semicolon (;) to mark the end of line, eliminating a whole class of errors that I tend to make in languages like Perl due to mistyping a character.

    You'll also notice that you didn't have to write "Hello World\n", as in Perl. This is because the print statement in Python is smart enough to assume that you usually want a newline after your prints. If you don't want a newline, just add a comma at the end. The comma operator inserts a space:

    print "hello", "world"

    produces the result:

    Hello World

    The example below concatenates the two strings without a space in between:

    print "Hello" + "World"

    produces the result:

    HelloWorld

    Python and Perl
    If Perl is the first post-modern programming language as Larry Wall (Perl's creator) describes it, then Python can be called the first neo-classical programming language.

    Both Python and Perl build on a strong understanding of the available tools for problem solving. Larry Wall used awk, sed, and shell scripting as the primary design inspirations when he started writing Perl because he was writing a language to make system administration tasks easier. Python was inspired more by object-oriented design and object-oriented tools.

    Rather than striving for a maximally expressive language as Larry Wall did, Guido van Rossum (the designer of Python) chose to create a simple, powerful, elegant base for creating systems out of components. The expressive power is still there in Python, but it tends to be compartmentalized, which makes reading Python code much easier. When you need more detail on how a certain line of code works, you look at the modules and functions it is using, rather than see the full complexity on the surface.

    Python and Tcl
    Tcl on the surface looks a lot like Python. Both languages can be used to write elegant, simple code. Tcl is primarily a string processing language. The only datatypes in Tcl are strings and one-dimensional arrays of strings.

    Python, in contrast, comes with a full range of data types including numbers (integers, long integers, floating point, octal, hex, and complex numbers), strings, lists, dictionaries (arrays indexed by keys, like hashes in Perl), and tuples (simple lists that can't be changed in place).

    Tcl and Python share the same GUI toolkit, Tk. Python's interface to Tk is called Tkinter, and it is included with all recent versions of Python. You are not limited to using just Tk to build GUIs in Python, however. You can also use the Gimp Tool Kit (GTK) and Gnome extensions to GTK+.

     
     
    >>> More Python Articles          >>> More By Evelyn Mitchell
     

       

    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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek