SunQuest
 
       Python
  Home arrow Python arrow Page 5 - 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 
Moblin 
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 - Milk And Toast And Honey


    (Page 5 of 6 )

    Like every programming language worth its salt, Python allows you to assign values to variables, the fundamental building blocks of any programming languages. Think of a variable as a container which can be used to store data; this data is used in different places in your Python program.

    A variable can store both numeric and non-numeric data, and the contents of a variable can be altered during program execution. Finally, variables can be compared with each other, and you - the programmer - can write program code that performs specific actions on the basis of this comparison.

    The manner in which variables are assigned values should be clear from the following example:

    >>> alpha = 99 >>> print alpha 99 >>> beta = 2 >>> print beta 2 >>> gamma = "Milk and toast and honey" >>> print gamma Milk and toast and honey >>>
    Although assigning values to a variable is extremely simple - as you've just seen - there are a few things that you should keep in mind here:

    * Every variable name must begin with a letter or underscore character (_), optionally followed by more letters or numbers - for example, "a", "data123", "i_am_god"

    * Case is important when referring to variables - in Python, a "cigar" is definitely not a "CIGAR"!

    * The equals (=) sign is used to assign a value to a variable.

    * It's always a good idea to give your variables names that make sense and are immediately recognizable - it's easy to tell what "net_profit" refers to, but not that easy to identify "np".

    * Unlike Java and C, Python does not require you to declare the type of variable prior to assigning it a value. It's behaviour here is closer to PHP, which allows you to assign any type of value to a variable without declaring it first.

    * Also like PHP, variables are created when they are assigned values - it is not necessary to declare them first.

    * Finally, Python variable names are not preceded with a $ sign, unlike most of its counterparts. Once you get used to it, you'll find that this actually adds to readability.

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