Home arrow Python arrow Page 5 - Python 101 (part 1): Snake Eyes

Milk And Toast And Honey - Python

Known for its power, flexibility and elegance - much like its namesake - Python is one of the most interesting programming languages around. In this introductory tutorial, find out how learning Python will earn you respect, affection and bags of money. Oh yeah...you might also learn a little bit about the origins, features and syntactical rules of the language.

  1. Python 101 (part 1): Snake Eyes
  2. The Jedi Master Speaks
  3. Start It Up
  4. Dissecting A Python...Program
  5. Milk And Toast And Honey
  6. Adding Things Up
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 15
May 29, 2001

print this article


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates


Dev Shed Tutorial Topics: