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  
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 101 (part 1): Snake Eyes
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    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:
      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 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

    - 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