Python
  Home arrow Python arrow Page 4 - Python 101 (part 1): Snake Eyes
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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

Python 101 (part 1): Snake Eyes
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2001-05-29

    Table of Contents:
  • Python 101 (part 1): Snake Eyes
  • The Jedi Master Speaks
  • Start It Up
  • Dissecting A Python...Program
  • Milk And Toast And Honey
  • Adding Things Up

  • 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

    Python 101 (part 1): Snake Eyes - Dissecting A Python...Program


    (Page 4 of 6 )

    Let's take a closer look at the script above. The first line

    #!/usr/bin/python
    is used to indicate the location of the Python binary. As I've just explained, this line must be included in each and every Python script, and its omission is a common cause of heartache for novice programmers. Make it a habit to include it, and you'll live a healthier, happier life.

    Next up, we have a comment.

    # eyes.py - print a line of output
    Comments in Python are preceded by a hash (#) symbol. If you're planning to make your code publicly available on the Internet, a comment is a great way to tell members of the opposite sex all about yourself - try including your phone number for optimum results. And, of course, it makes it easier for other developers (not to mention you, circa 2010) to read and understand your code.

    And finally, the meat of the script:

    print "Snake Eyes"
    In Python, a line of code like the one above is called a "statement". Every Python program is a collection of statements, and a statement usually contains instructions to be carried out by the Python interpreter. In this particular statement, the print() function has been used to send a line of text to the screen. Like all programming languages, Python comes with a set of built-in functions - the print() function is one you'll be seeing a lot of in the future. The text to be printed is included within single or double quotes.

    Just as you print text, you can also print numbers...

    Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> print 4 4 >>> print 3443634 3443634 >>>
    ...or the results of numeric calculations.

    >>> print 24+1 25 >>> print 12*10 120 >>>
    Although every Python statement usually begins on a new line, a single statement can be split across lines with a backslash (). It is not necessary to end each statement with a semicolon (;), as in Perl and PHP.

    >>> print ... "Snake Ey ... es" Snake Eyes >>>

    More Python Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    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 5 hosted by Hostway