Saturday, January 30, 2010


Python Set Types:

A set type is a collection data type that supports the membership operator (in), the size function (len()), and is iterable. In addition, set types at least provide a set.isdisjoint() method, and support for comparisons, as well as support for the bitwise operators (which in the context of sets are used for union, intersection, etc.).

Python provides two built-in set types: the mutable set type and the immutable frozenset.

When iterated, set types provide their items in an arbitrary order.

Friday, December 18, 2009


Simple example python script:

name = raw_input(" What is your pet name? ")
print "Hello, " + name + "!"

If you run this (remember to save it first), you should see the following prompt
in the inter-preter window: What is your pet name?

Enter your pet name (for example, Bunny) and press Enter.
You should get something like this:

What is your pet name? // You enter your pet name: Bunny //
Hello, Bunny!

Wednesday, November 25, 2009


Python Collection Data Types:

A sequence type is one that supports the membership operator (in), the size function (len()), slices ([]), and is iterable.

Python provides five built-in sequence types: bytearray, bytes, list, str, and tuple.

Some other sequence types are provided in the standard library, most notably, collections.namedtuple.

Saturday, October 31, 2009

test3

Wednesday, September 30, 2009

test2

Monday, August 31, 2009


Test

Test

Thursday, July 23, 2009


Python Width and Precision:

A conversion specifier may include a field width and a precision. 
The width is the minimum number of characters reserved for a formatted value. The precision is (for a numeric conver-sion) the number of decimals that will be included in the result or (for a string conversion) the maximum number of characters the formatted value may have.

These two parameters are supplied as two integer numbers (width first, then precision), 
separated by a . (dot). Both are optional, but if you want to supply only the precision, 
you must also include the dot:

>>> '%10f' % pi      # Field width 10
'  3.141593'

>>> '%10.2f' % pi    # Field width 10, precision 2
'      3.14'
>>> '%.2f' % pi      # Precision 2
'3.14'
>>> '%.5s' % 'Guido van Rossum'
'Guido'

You can use an * (asterisk) as the width or precision (or both). 
In that case, the number will be read from the tuple argument:

>>> '%.*s' % (5, 'Guido van Rossum')
'Guido'

Python Simple Conversion:

The simple conversion, with only a conversion type, is really easy to use:

>>> 'Using str: %s' % 99L
'Using str: 99'

>>> 'Using repr: %r' % 99L
'Using repr: 99L'

>>> 'Price of eggs: $%d' % 42
'Price of eggs: $42'

>>> 'Hexadecimal price of eggs: %x' % 42
'Hexadecimal price of eggs: 2a'

>>> from math import pi
>>> 'Pi: %f...' % pi
'Pi: 3.141593...'

>>> 'Very inexact estimate of pi: %i' % pi
'Very inexact estimate of pi: 3'