<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.darenet.org/skins/common/feed.css?12"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.darenet.org/index.php?feed=atom&amp;target=Swaroop&amp;title=Special%3AContributions</id>
		<title>DareNET Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.darenet.org/index.php?feed=atom&amp;target=Swaroop&amp;title=Special%3AContributions"/>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Special:Contributions/Swaroop"/>
		<updated>2026-05-21T05:32:03Z</updated>
		<subtitle>From DareNET Wiki</subtitle>
		<generator>MediaWiki 1.15.1</generator>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Basics</id>
		<title>Python en:Basics</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Basics"/>
				<updated>2009-03-31T18:48:24Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* Logical And Physical Lines */ Improving sentence, thanks to Vincent Zee&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just printing 'Hello World' is not enough, is it? You want to do more than that - you want to take some input, manipulate it and get something out of it. We can achieve this in Python using constants and variables.&lt;br /&gt;
&lt;br /&gt;
== Literal Constants ==&lt;br /&gt;
&lt;br /&gt;
An example of a literal constant is a number like &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;1.23&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;9.25e-3&amp;lt;/tt&amp;gt; or a string like &amp;lt;tt&amp;gt;'This is a string'&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;&amp;quot;It's a string!&amp;quot;&amp;lt;/tt&amp;gt;. It is called a literal because it is ''literal'' - you use its value literally. The number &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; always represents itself and nothing else - it is a ''constant'' because its value cannot be changed. Hence, all these are referred to as literal constants.&lt;br /&gt;
&lt;br /&gt;
== Numbers ==&lt;br /&gt;
&lt;br /&gt;
Numbers in Python are of three types - integers, floating point and complex numbers.&lt;br /&gt;
&lt;br /&gt;
* An examples of an integer is &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; which is just a whole number.&lt;br /&gt;
* Examples of floating point numbers (or ''floats'' for short) are &amp;lt;tt&amp;gt;3.23&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;52.3E-4&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;E&amp;lt;/tt&amp;gt; notation indicates powers of 10. In this case, &amp;lt;tt&amp;gt;52.3E-4&amp;lt;/tt&amp;gt; means &amp;lt;tt&amp;gt;52.3 * 10&amp;lt;sup&amp;gt;-4&amp;lt;/sup&amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Examples of complex numbers are &amp;lt;tt&amp;gt;(-5+4j)&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;(2.3 - 4.6j)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Note for Experienced Programmers&lt;br /&gt;
: There is no separate 'long int' type. The default integer type can be any large value.&lt;br /&gt;
&lt;br /&gt;
== Strings ==&lt;br /&gt;
&lt;br /&gt;
A string is a ''sequence'' of ''characters''. Strings are basically just a bunch of words. The words can be in English or any other language that is supported in the Unicode standard, which means [http://www.unicode.org/faq/basic_q.html#16 almost any language in the world].&lt;br /&gt;
&lt;br /&gt;
; Note for Experienced Programmers&lt;br /&gt;
: There are no &amp;quot;ASCII-only&amp;quot; strings because Unicode is a superset of ASCII. If a strictly ASCII-encoded byte-stream is needed, then use &amp;lt;tt&amp;gt;str.encode(&amp;quot;ascii&amp;quot;)&amp;lt;/tt&amp;gt;. For more details, please see the [http://stackoverflow.com/questions/175240/how-do-i-convert-a-files-format-from-unicode-to-ascii-using-python#175270 related discussion at StackOverflow].&lt;br /&gt;
: By default, all strings are in Unicode.&lt;br /&gt;
&lt;br /&gt;
I can almost guarantee that you will be using strings in almost every Python program that you write, so pay attention to the following part on how to use strings in Python.&lt;br /&gt;
&lt;br /&gt;
===  Single Quotes ===&lt;br /&gt;
&lt;br /&gt;
You can specify strings using single quotes such as &amp;lt;tt&amp;gt;'Quote me on this'&amp;lt;/tt&amp;gt;. All white space i.e. spaces and tabs are preserved as-is.&lt;br /&gt;
&lt;br /&gt;
=== Double Quotes ===&lt;br /&gt;
&lt;br /&gt;
Strings in double quotes work exactly the same way as strings in single quotes. An example is &amp;lt;tt&amp;gt;&amp;quot;What's your name?&amp;quot;&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Triple Quotes ===&lt;br /&gt;
&lt;br /&gt;
You can specify multi-line strings using triple quotes - (&amp;quot;&amp;quot;&amp;quot; or &amp;lt;nowiki&amp;gt;'''&amp;lt;/nowiki&amp;gt;). You can use single quotes and double quotes freely within the triple quotes. An example is:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;nowiki&amp;gt;'''This is a multi-line string. This is the first line.&lt;br /&gt;
    This is the second line.&lt;br /&gt;
    &amp;quot;What's your name?,&amp;quot; I asked.&lt;br /&gt;
    He said &amp;quot;Bond, James Bond.&amp;quot;&lt;br /&gt;
    '''&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Escape Sequences ===&lt;br /&gt;
&lt;br /&gt;
Suppose, you want to have a string which contains a single quote (&amp;lt;tt&amp;gt;'&amp;lt;/tt&amp;gt;), how will you specify this string? For example, the string is &amp;lt;tt&amp;gt;What's your name?&amp;lt;/tt&amp;gt;. You cannot specify &amp;lt;tt&amp;gt;'What's your name?'&amp;lt;/tt&amp;gt; because Python will be confused as to where the string starts and ends. So, you will have to specify that this single quote does not indicate the end of the string. This can be done with the help of what is called an ''escape sequence''. You specify the single quote as &amp;lt;tt&amp;gt;\'&amp;lt;/tt&amp;gt; - notice the backslash. Now, you can specify the string as &amp;lt;tt&amp;gt;'What\'s your name?'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another way of specifying this specific string would be &amp;lt;tt&amp;gt;&amp;quot;What's your name?&amp;quot;&amp;lt;/tt&amp;gt; i.e. using double quotes. Similarly, you have to use an escape sequence for using a double quote itself in a double quoted string. Also, you have to indicate the backslash itself using the escape sequence &amp;lt;tt&amp;gt;\\&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
What if you wanted to specify a two-line string? One way is to use a triple-quoted string as shown [[#Triple Quotes|previously]] or you can use an escape sequence for the newline character - &amp;lt;tt&amp;gt;\n&amp;lt;/tt&amp;gt; to indicate the start of a new line. An example is &amp;lt;tt&amp;gt;This is the first line\nThis is the second line&amp;lt;/tt&amp;gt;. Another useful escape sequence to know is the tab - &amp;lt;tt&amp;gt;\t&amp;lt;/tt&amp;gt;. There are many more escape sequences but I have mentioned only the most useful ones here.&lt;br /&gt;
&lt;br /&gt;
One thing to note is that in a string, a single backslash at the end of the line indicates that the string is continued in the next line, but no newline is added. For example:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;This is the first sentence.\&lt;br /&gt;
    This is the second sentence.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
is equivalent to &amp;lt;tt&amp;gt;&amp;quot;This is the first sentence. This is the second sentence.&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Raw Strings ===&lt;br /&gt;
&lt;br /&gt;
If you need to specify some strings where no special processing such as escape sequences are handled, then what you need is to specify a ''raw'' string by prefixing &amp;lt;tt&amp;gt;r&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;R&amp;lt;/tt&amp;gt; to the string. An example is &amp;lt;tt&amp;gt;r&amp;quot;Newlines are indicated by \n&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Strings Are Immutable ===&lt;br /&gt;
&lt;br /&gt;
This means that once you have created a string, you cannot change it. Although this might seem like a bad thing, it really isn't. We will see why this is not a limitation in the various programs that we see later on.&lt;br /&gt;
&lt;br /&gt;
=== String Literal Concatenation ===&lt;br /&gt;
&lt;br /&gt;
If you place two string literals side by side, they are automatically concatenated by Python. For example, &amp;lt;tt&amp;gt;'What\'s ' 'your name?'&amp;lt;/tt&amp;gt; is automatically converted in to &amp;lt;tt&amp;gt;&amp;quot;What's your name?&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; Note for C/C++ Programmers&lt;br /&gt;
: There is no separate &amp;lt;tt&amp;gt;char&amp;lt;/tt&amp;gt; data type in Python. There is no real need for it and I am sure you won't miss it.&lt;br /&gt;
&lt;br /&gt;
; Note for Perl/PHP Programmers&lt;br /&gt;
: Remember that single-quoted strings and double-quoted strings are the same - they do not differ in any way.&lt;br /&gt;
&lt;br /&gt;
; Note for Regular Expression Users&lt;br /&gt;
: Always use raw strings when dealing with regular expressions. Otherwise, a lot of backwhacking may be required. For example, backreferences can be referred to as &amp;lt;tt&amp;gt;'\\1'&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;r'\1'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== The format Method ===&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want to construct strings from other information. This is where the &amp;lt;tt&amp;gt;format()&amp;lt;/tt&amp;gt; method is useful.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: str_format.py&lt;br /&gt;
&lt;br /&gt;
age = 25&lt;br /&gt;
name = 'Swaroop'&lt;br /&gt;
&lt;br /&gt;
print('{0} is {1} years old'.format(name, age))&lt;br /&gt;
print('Why is {0} playing with that python?'.format(name))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python str_format.py&lt;br /&gt;
    Swaroop is 25 years old&lt;br /&gt;
    Why is Swaroop playing with that python?&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
A string can use certain specifications and subsequently, the ''format'' method can be called to substitute those specifications with corresponding arguments to the &amp;lt;tt&amp;gt;format&amp;lt;/tt&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
Observe the first usage where we use &amp;lt;tt&amp;gt;{0}&amp;lt;/tt&amp;gt; and this corresponds to the variable &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; which is the first argument to the format method. Similarly, the second specification is &amp;lt;tt&amp;gt;{1}&amp;lt;/tt&amp;gt; corresponding to &amp;lt;tt&amp;gt;age&amp;lt;/tt&amp;gt; which is the second argument to the format method.&lt;br /&gt;
&lt;br /&gt;
Notice that we could achieved the same using string concatenation: &amp;lt;tt&amp;gt;name + ' is ' + str(age) + ' years old'&amp;lt;/tt&amp;gt; but notice how much uglier and error-prone this is. Second, the conversion to string would be done automatically by the &amp;lt;tt&amp;gt;format&amp;lt;/tt&amp;gt; method instead of the explicit conversion here. Third, when using the &amp;lt;tt&amp;gt;format&amp;lt;/tt&amp;gt; method, we can change the message without having to deal with the variables used and vice-versa.&lt;br /&gt;
&lt;br /&gt;
What Python does in the &amp;lt;tt&amp;gt;format&amp;lt;/tt&amp;gt; method is that it substitutes each argument value into the place of the specification. There can be more detailed specifications such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; '{0:.3}'.format(1/3) # decimal (.) precision of 3 for float&lt;br /&gt;
'0.333'&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; '{0:_^11}'.format('hello') # fill with underscores (_) with the text centered (^) to 11 width&lt;br /&gt;
'___hello___'&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; '{name} wrote {book}'.format(name='Swaroop', book='A Byte of Python') # keyword-based&lt;br /&gt;
'Swaroop wrote A Byte of Python'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Details of this formatting specification is explained in the [http://www.python.org/dev/peps/pep-3101/ Python Enhancement Proposal No. 3101].&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
&lt;br /&gt;
Using just literal constants can soon become boring - we need some way of storing any information and manipulate them as well. This is where ''variables'' come into the picture. Variables are exactly what the name implies - their value can vary, i.e.,  you can store anything using a variable. Variables are just parts of your computer's memory where you store some information. Unlike literal constants, you need some method of accessing these variables and hence you give them names.&lt;br /&gt;
&lt;br /&gt;
== Identifier Naming ==&lt;br /&gt;
&lt;br /&gt;
Variables are examples of identifiers. ''Identifiers'' are names given to identify ''something''. There are some rules you have to follow for naming identifiers:&lt;br /&gt;
&lt;br /&gt;
* The first character of the identifier must be a letter of the alphabet (uppercase ASCII or lowercase ASCII or Unicode character) or an underscore ('_').&lt;br /&gt;
* The rest of the identifier name can consist of letters (uppercase ASCII or lowercase ASCII or Unicode character), underscores ('_') or digits (0-9).&lt;br /&gt;
* Identifier names are case-sensitive. For example, &amp;lt;tt&amp;gt;myname&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;myName&amp;lt;/tt&amp;gt; are '''not''' the same. Note the lowercase &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; in the former and the uppercase &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; in the latter.&lt;br /&gt;
* Examples of ''valid'' identifier names are &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;__my_name&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;name_23&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;a1b2_c3&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;resumÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â©_count&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Examples of ''invalid'' identifier names are &amp;lt;tt&amp;gt;2things&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;this is spaced out&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;my-name&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;&amp;quot;this_is_in_quotes&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data Types ==&lt;br /&gt;
&lt;br /&gt;
Variables can hold values of different types called '''data types'''. The basic types are numbers and strings, which we have already discussed. In later chapters, we will see how to create our own types using [[Python_en:Object Oriented Programming|classes]].&lt;br /&gt;
&lt;br /&gt;
== Objects ==&lt;br /&gt;
&lt;br /&gt;
Remember, Python refers to anything used in a program as an ''object''.  This is meant in the generic sense. Instead of saying 'the ''something''&amp;lt;nowiki&amp;gt;'&amp;lt;/nowiki&amp;gt;, we say 'the ''object''&amp;lt;nowiki&amp;gt;'&amp;lt;/nowiki&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; Note for Object Oriented Programming users&lt;br /&gt;
: Python is strongly object-oriented in the sense that everything is an object including numbers, strings and functions.&lt;br /&gt;
&lt;br /&gt;
We will now see how to use variables along with literal constants. Save the following example and run the program.&lt;br /&gt;
&lt;br /&gt;
; How to write Python programs&lt;br /&gt;
: Henceforth, the standard procedure to save and run a Python program is as follows:&lt;br /&gt;
:# Open your favorite editor.&lt;br /&gt;
:# Enter the program code given in the example.&lt;br /&gt;
:# Save it as a file with the filename mentioned in the comment. I follow the convention of having all Python programs saved with the extension &amp;lt;tt&amp;gt;.py&amp;lt;/tt&amp;gt;.&lt;br /&gt;
:# Run the interpreter with the command &amp;lt;tt&amp;gt;python program.py&amp;lt;/tt&amp;gt; or use IDLE to run the programs. You can also use the [[Python_en:First Steps#Executable Python Programs|executable method]] as explained earlier.&lt;br /&gt;
&lt;br /&gt;
=== Example: Using Variables And Literal Constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Filename : var.py&lt;br /&gt;
&lt;br /&gt;
i = 5&lt;br /&gt;
print(i)&lt;br /&gt;
i = i + 1&lt;br /&gt;
print(i)&lt;br /&gt;
&lt;br /&gt;
s = '''This is a multi-line string.&lt;br /&gt;
This is the second line.'''&lt;br /&gt;
print(s)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python var.py&lt;br /&gt;
    5&lt;br /&gt;
    6&lt;br /&gt;
    This is a multi-line string.&lt;br /&gt;
    This is the second line.&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Here's how this program works. First, we assign the literal constant value &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; to the variable &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; using the assignment operator (&amp;lt;tt&amp;gt;=&amp;lt;/tt&amp;gt;). This line is called a statement because it states that something should be done and in this case, we connect the variable name &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; to the value &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt;.  Next, we print the value of &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; using the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; statement which, unsurprisingly, just prints the value of the variable to the screen.&lt;br /&gt;
&lt;br /&gt;
Then we add &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; to the value stored in &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; and store it back. We then print it and expectedly, we get the value &amp;lt;tt&amp;gt;6&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Similarly, we assign the literal string to the variable &amp;lt;tt&amp;gt;s&amp;lt;/tt&amp;gt; and then print it.&lt;br /&gt;
&lt;br /&gt;
; Note for static language programmers&lt;br /&gt;
: Variables are used by just assigning them a value. No declaration or data type definition is needed/used.&lt;br /&gt;
&lt;br /&gt;
== Logical And Physical Lines ==&lt;br /&gt;
&lt;br /&gt;
A physical line is what you ''see'' when you write the program. A logical line is what ''Python sees'' as a single statement. Python implicitly assumes that each ''physical line'' corresponds to a ''logical line''.&lt;br /&gt;
&lt;br /&gt;
An example of a logical line is a statement like &amp;lt;tt&amp;gt;print('Hello World')&amp;lt;/tt&amp;gt; - if this was on a line by itself (as you see it in an editor), then this also corresponds to a physical line.&lt;br /&gt;
&lt;br /&gt;
Implicitly, Python encourages the use of a single statement per line which makes code more readable.&lt;br /&gt;
&lt;br /&gt;
If you want to specify more than one logical line on a single physical line, then you have to explicitly specify this using a semicolon (&amp;lt;tt&amp;gt;;&amp;lt;/tt&amp;gt;) which indicates the end of a logical line/statement. For example,&lt;br /&gt;
&lt;br /&gt;
    i = 5&lt;br /&gt;
    print(i)&lt;br /&gt;
&lt;br /&gt;
is effectively same as&lt;br /&gt;
&lt;br /&gt;
    i = 5;&lt;br /&gt;
    print(i);&lt;br /&gt;
&lt;br /&gt;
and the same can be written as&lt;br /&gt;
&lt;br /&gt;
    i = 5; print(i);&lt;br /&gt;
&lt;br /&gt;
or even&lt;br /&gt;
&lt;br /&gt;
    i = 5; print(i)&lt;br /&gt;
&lt;br /&gt;
However, I '''strongly recommend''' that you stick to '''writing a single logical line in a single physical line only'''. Use more than one physical line for a single logical line only if the logical line is really long. The idea is to avoid the semicolon as much as possible since it leads to more readable code. In fact, I have ''never'' used or even seen a semicolon in a Python program.&lt;br /&gt;
&lt;br /&gt;
An example of writing a logical line spanning many physical lines follows. This is referred to as '''explicit line joining'''.&lt;br /&gt;
&lt;br /&gt;
    s = 'This is a string. \&lt;br /&gt;
    This continues the string.'&lt;br /&gt;
    print(s)&lt;br /&gt;
&lt;br /&gt;
This gives the output:&lt;br /&gt;
&lt;br /&gt;
    This is a string. This continues the string.&lt;br /&gt;
&lt;br /&gt;
Similarly,&lt;br /&gt;
&lt;br /&gt;
    print\&lt;br /&gt;
    (i)&lt;br /&gt;
&lt;br /&gt;
is the same as&lt;br /&gt;
&lt;br /&gt;
    print(i)&lt;br /&gt;
&lt;br /&gt;
Sometimes, there is an implicit assumption where you don't need to use a backslash. This is the case where the logical line uses parentheses, square brackets or curly braces. This is is called '''implicit line joining'''.  You can see this in action when we write programs using [[Python_en:Data Structures#Lists|lists]] in later chapters.&lt;br /&gt;
&lt;br /&gt;
== Indentation ==&lt;br /&gt;
&lt;br /&gt;
Whitespace is important in Python. Actually, '''whitespace at the beginning of the line is important'''. This is called '''indentation'''. Leading whitespace (spaces and tabs) at the beginning of the logical line is used to determine the indentation level of the logical line, which in turn is used to determine the grouping of statements.&lt;br /&gt;
&lt;br /&gt;
This means that statements which go together '''must''' have the same indentation. Each such set of statements is called a '''block'''. We will see examples of how blocks are important in later chapters.&lt;br /&gt;
&lt;br /&gt;
One thing you should remember is that wrong indentation can give rise to errors. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
i = 5&lt;br /&gt;
 print('Value is ', i) # Error! Notice a single space at the start of the line&lt;br /&gt;
print('I repeat, the value is ', i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you run this, you get the following error:&lt;br /&gt;
&lt;br /&gt;
      File &amp;quot;whitespace.py&amp;quot;, line 4&lt;br /&gt;
        print('Value is ', i) # Error! Notice a single space at the start of the line&lt;br /&gt;
        ^&lt;br /&gt;
    IndentationError: unexpected indent&lt;br /&gt;
&lt;br /&gt;
Notice that there is a single space at the beginning of the second line. The error indicated by Python tells us that the syntax of the program is invalid i.e. the program was not properly written. What this means to you is that ''you cannot arbitrarily start new blocks of statements'' (except for the default main block which you have been using all along, of course). Cases where you can use new blocks will be detailed in later chapters such as the [[Python_en:Control Flow|control flow chapter]].&lt;br /&gt;
&lt;br /&gt;
; How to indent&lt;br /&gt;
: Do '''not''' use a mixture of tabs and spaces for the indentation as it does not work across different platforms properly. I ''strongly recommend'' that you use a ''single tab'' or ''four spaces'' for each indentation level.&lt;br /&gt;
: Choose either of these two indentation styles. More importantly, choose one and use it '''consistently''' i.e. use that indentation style ''only''.&lt;br /&gt;
&lt;br /&gt;
; Note to static language programmers&lt;br /&gt;
: Python will always use indentation for blocks and will never use braces. Run &amp;lt;tt&amp;gt;from __future__ import braces&amp;lt;/tt&amp;gt; to learn more.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Now that we have gone through many nitty-gritty details, we can move on to more interesting stuff such as control flow statements. Be sure to become comfortable with what you have read in this chapter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:First Steps|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Operators and Expressions|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Basics]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Modules</id>
		<title>Python en:Modules</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Modules"/>
				<updated>2009-03-30T12:56:19Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
You have seen how you can reuse code in your program by defining functions once. What if you wanted to reuse a number of functions in other programs that you write? As you might have guessed, the answer is modules.&lt;br /&gt;
&lt;br /&gt;
There are various methods of writing modules, but the simplest way is to create a file with a &amp;lt;tt&amp;gt;.py&amp;lt;/tt&amp;gt; extension that contains functions and variables.&lt;br /&gt;
&lt;br /&gt;
Another method is to write the modules in the native language in which the Python interpreter itself was written. For example, you can write modules in the [http://docs.python.org/extending/ C programming language] and when compiled, they can be used from your Python code when using the standard Python interpreter.&lt;br /&gt;
&lt;br /&gt;
A module can be ''imported'' by another program to make use of its functionality. This is how we can use the Python standard library as well. First, we will see how to use the standard library modules.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_sys.py&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
print('The command line arguments are:')&lt;br /&gt;
for i in sys.argv:&lt;br /&gt;
    print(i)&lt;br /&gt;
&lt;br /&gt;
print('\n\nThe PYTHONPATH is', sys.path, '\n')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_sys.py we are arguments&lt;br /&gt;
    The command line arguments are:&lt;br /&gt;
    using_sys.py&lt;br /&gt;
    we&lt;br /&gt;
    are&lt;br /&gt;
    arguments&lt;br /&gt;
    &lt;br /&gt;
    The PYTHONPATH is [&amp;lt;nowiki&amp;gt;''&amp;lt;/nowiki&amp;gt;, 'C:\\Windows\\system32\\python30.zip',&lt;br /&gt;
    'C:\\Python30\\DLLs', 'C:\\Python30\\lib',&lt;br /&gt;
    'C:\\Python30\\lib\\plat-win', 'C:\\Python30', &lt;br /&gt;
    'C:\\Python30\\lib\\site-packages']&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
First, we ''import'' the &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module using the &amp;lt;tt&amp;gt;import&amp;lt;/tt&amp;gt; statement. Basically, this translates to us telling Python that we want to use this module. The &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module contains functionality related to the Python interpreter and its environment i.e. the ''sys''tem.&lt;br /&gt;
&lt;br /&gt;
When Python executes the &amp;lt;tt&amp;gt;import sys&amp;lt;/tt&amp;gt; statement, it looks for the &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module. In this case, it is one of the built-in modules, and hence Python knows where to find it.&lt;br /&gt;
&lt;br /&gt;
If it was not a compiled module i.e. a module written in Python, then the Python interpreter will search for it in the directories listed in its &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt; variable. If the module is found, then the statements in the body of that module is run and then the module is made ''available'' for you to use. Note that the initialization is done only the ''first'' time that we import a module.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;argv&amp;lt;/tt&amp;gt; variable in the &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module is accessed using the dotted notation i.e. &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt;. It clearly indicates that this name is part of the &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module. Another advantage of this approach is that the name does not clash with any &amp;lt;tt&amp;gt;argv&amp;lt;/tt&amp;gt; variable used in your program. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt; variable is a ''list'' of strings (lists are explained in detail in a later [[Python_en:Data Structures#Lists|chapter]]. Specifically, the &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt; contains the list of ''command line arguments'' i.e. the arguments passed to your program using the command line.&lt;br /&gt;
&lt;br /&gt;
If you are using an IDE to write and run these programs, look for a way to specify command line arguments to the program in the menus.&lt;br /&gt;
&lt;br /&gt;
Here, when we execute &amp;lt;tt&amp;gt;python using_sys.py we are arguments&amp;lt;/tt&amp;gt;, we run the module &amp;lt;tt&amp;gt;using_sys.py&amp;lt;/tt&amp;gt; with the &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; command and the other things that follow are arguments passed to the program. Python stores the command line arguments in the &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt; variable for us to use.&lt;br /&gt;
&lt;br /&gt;
Remember, the name of the script running is always the first argument in the &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt; list. So, in this case we will have &amp;lt;tt&amp;gt;'using_sys.py'&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;sys.argv[0]&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'we'&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;sys.argv[1]&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'are'&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;sys.argv[2]&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;'arguments'&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;sys.argv[3]&amp;lt;/tt&amp;gt;. Notice that Python starts counting from 0 and not 1.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt; contains the list of directory names where modules are imported from. Observe that the first string in &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt; is empty - this empty string indicates that the current directory is also part of the &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt; which is same as the &amp;lt;tt&amp;gt;PYTHONPATH&amp;lt;/tt&amp;gt; environment variable. This means that you can directly import modules located in the current directory. Otherwise, you will have to place your module in one of the directories listed in &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that the current directory is the directory from which the program is launched. Run &amp;lt;tt&amp;gt;import os; print(os.getcwd())&amp;lt;/tt&amp;gt; to find out the current directory of your program.&lt;br /&gt;
&lt;br /&gt;
== Byte-compiled .pyc files ==&lt;br /&gt;
&lt;br /&gt;
Importing a module is a relatively costly affair, so Python does some tricks to make it faster. One way is to create ''byte-compiled'' files with the extension &amp;lt;tt&amp;gt;.pyc&amp;lt;/tt&amp;gt; which is an intermediate form that Python transforms the program into (remember the [[Python_en:Introduction|introduction section]] on how Python works?). This &amp;lt;tt&amp;gt;.pyc&amp;lt;/tt&amp;gt; file is useful when you import the module the next time from a different program - it will be much faster since a portion of the processing required in importing a module is already done. Also, these byte-compiled files are platform-independent.&lt;br /&gt;
&lt;br /&gt;
; Note&lt;br /&gt;
: These &amp;lt;tt&amp;gt;.pyc&amp;lt;/tt&amp;gt; files are usually created in the same directory as the corresponding &amp;lt;tt&amp;gt;.py&amp;lt;/tt&amp;gt; files. If Python does not have permission to write to files in that directory, then the &amp;lt;tt&amp;gt;.pyc&amp;lt;/tt&amp;gt; files will not be created.&lt;br /&gt;
&lt;br /&gt;
== The from ... import ... statement ==&lt;br /&gt;
&lt;br /&gt;
If you want to directly import the &amp;lt;tt&amp;gt;argv&amp;lt;/tt&amp;gt; variable into your program (to avoid typing the &amp;lt;tt&amp;gt;sys.&amp;lt;/tt&amp;gt; everytime for it), then you can use the &amp;lt;tt&amp;gt;from sys import argv&amp;lt;/tt&amp;gt; statement. If you want to import all the names used in the &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module, then you can use the &amp;lt;tt&amp;gt;from sys import *&amp;lt;/tt&amp;gt; statement. This works for any module.&lt;br /&gt;
&lt;br /&gt;
In general, you ''should avoid'' using this statement and use the &amp;lt;tt&amp;gt;import&amp;lt;/tt&amp;gt; statement instead since your program will avoid name clashes and will be more readable.&lt;br /&gt;
&lt;br /&gt;
== A module's __name__ ==&lt;br /&gt;
&lt;br /&gt;
Every module has a name and statements in a module can find out the name of its module. This is handy in the particular situation of figuring out if the module is being run standalone or being imported. As mentioned previously, when a module is imported for the first time, the code in that module is executed. We can use this concept to alter the behavior of the module if the program was used by itself and not when it was imported from another module. This can be achieved using the &amp;lt;tt&amp;gt;__name__&amp;lt;/tt&amp;gt; attribute of the module.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_name.py&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    print('This program is being run by itself')&lt;br /&gt;
else:&lt;br /&gt;
    print('I am being imported from another module')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_name.py&lt;br /&gt;
    This program is being run by itself&lt;br /&gt;
    &lt;br /&gt;
    $ python&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; import using_name&lt;br /&gt;
    I am being imported from another module&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Every Python module has it's &amp;lt;tt&amp;gt;__name__&amp;lt;/tt&amp;gt; defined and if this is &amp;lt;tt&amp;gt;'__main__'&amp;lt;/tt&amp;gt;, it implies that the module is being run standalone by the user and we can take appropriate actions.&lt;br /&gt;
&lt;br /&gt;
== Making Your Own Modules ==&lt;br /&gt;
&lt;br /&gt;
Creating your own modules is easy, you've been doing it all along! This is because every Python program is also a module. You just have to make sure it has a &amp;lt;tt&amp;gt;.py&amp;lt;/tt&amp;gt; extension. The following example should make it clear.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: mymodule.py&lt;br /&gt;
&lt;br /&gt;
def sayhi():&lt;br /&gt;
    print('Hi, this is mymodule speaking.')&lt;br /&gt;
&lt;br /&gt;
__version__ = '0.1'&lt;br /&gt;
&lt;br /&gt;
# End of mymodule.py&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above was a sample ''module''. As you can see, there is nothing particularly special about compared to our usual Python program. We will next see how to use this module in our other Python programs.&lt;br /&gt;
&lt;br /&gt;
Remember that the module should be placed in the same directory as the program that we import it in, or the module should be in one of the directories listed in &amp;lt;tt&amp;gt;sys.path&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: mymodule_demo.py&lt;br /&gt;
&lt;br /&gt;
import mymodule&lt;br /&gt;
&lt;br /&gt;
mymodule.sayhi()&lt;br /&gt;
print ('Version', mymodule.__version__)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python mymodule_demo.py&lt;br /&gt;
    Hi, this is mymodule speaking.&lt;br /&gt;
    Version 0.1&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Notice that we use the same dotted notation to access members of the module. Python makes good reuse of the same notation to give the distinctive 'Pythonic' feel to it so that we don't have to keep learning new ways to do things.&lt;br /&gt;
&lt;br /&gt;
Here is a version utilising the &amp;lt;tt&amp;gt;from..import&amp;lt;/tt&amp;gt; syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: mymodule_demo2.py&lt;br /&gt;
&lt;br /&gt;
from mymodule import sayhi, __version__&lt;br /&gt;
&lt;br /&gt;
sayhi()&lt;br /&gt;
print('Version', __version__)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output of &amp;lt;tt&amp;gt;mymodule_demo2.py&amp;lt;/tt&amp;gt; is same as the output of &amp;lt;tt&amp;gt;mymodule_demo.py&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Notice that if there was already a &amp;lt;tt&amp;gt;__version__&amp;lt;/tt&amp;gt; name declared in the module that imports mymodule, there would be a clash. This is also likely because it is common practice for each module to declare it's version number using this name. Hence, it is always recommended to prefer the &amp;lt;tt&amp;gt;import&amp;lt;/tt&amp;gt; statement even though it might make your program a little longer.&lt;br /&gt;
&lt;br /&gt;
You could also use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from mymodule import *&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will import all public names such as &amp;lt;tt&amp;gt;sayhi&amp;lt;/tt&amp;gt; but would not import &amp;lt;tt&amp;gt;__version__&amp;lt;/tt&amp;gt; because it starts with double underscores.&lt;br /&gt;
&lt;br /&gt;
; Zen of Python&lt;br /&gt;
: One of Python's guiding principles is that &amp;quot;Explicit is better than Implicit&amp;quot;. Run &amp;lt;tt&amp;gt;import this&amp;lt;/tt&amp;gt; to learn more and see [http://stackoverflow.com/questions/228181/zen-of-python this discussion] which lists examples for each of the principles.&lt;br /&gt;
&lt;br /&gt;
== The dir function ==&lt;br /&gt;
&lt;br /&gt;
You can use the built-in &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; function to list the identifiers that an object defines. For example, for a module, the identifiers include the functions, classes and variables defined in that module.&lt;br /&gt;
&lt;br /&gt;
When you supply a module name to the &amp;lt;tt&amp;gt;dir()&amp;lt;/tt&amp;gt; function, it returns the list of the names defined in that module. When no argument is applied to it, it returns the list of names defined in the current module.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
$ python&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import sys # get list of attributes, in this case, for the sys module&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; dir(sys)&lt;br /&gt;
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__s&lt;br /&gt;
tderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_compact_freelists',&lt;br /&gt;
'_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', '&lt;br /&gt;
byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle'&lt;br /&gt;
, 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable',&lt;br /&gt;
'exit', 'flags', 'float_info', 'getcheckinterval', 'getdefaultencoding', 'getfil&lt;br /&gt;
esystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof',&lt;br /&gt;
 'gettrace', 'getwindowsversion', 'hexversion', 'intern', 'maxsize', 'maxunicode&lt;br /&gt;
', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platfor&lt;br /&gt;
m', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setprofile', 'setrecursionlimit&lt;br /&gt;
', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_in&lt;br /&gt;
fo', 'warnoptions', 'winver']&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; dir() # get list of attributes for current module&lt;br /&gt;
['__builtins__', '__doc__', '__name__', '__package__', 'sys']&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = 5 # create a new variable 'a'&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; dir()&lt;br /&gt;
['__builtins__', '__doc__', '__name__', '__package__', 'a', 'sys']&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; del a # delete/remove a name&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; dir()&lt;br /&gt;
['__builtins__', '__doc__', '__name__', '__package__', 'sys']&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
First, we see the usage of &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; on the imported &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module. We can see the huge list of attributes that it contains.&lt;br /&gt;
&lt;br /&gt;
Next, we use the &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; function without passing parameters to it. By default, it returns the list of attributes for the current module. Notice that the list of imported modules is also part of this list.&lt;br /&gt;
&lt;br /&gt;
In order to observe the &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; in action, we define a new variable &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; and assign it a value and then check &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; and we observe that there is an additional value in the list of the same name. We remove the variable/attribute of the current module using the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; statement and the change is reflected again in the output of the &amp;lt;tt&amp;gt;dir&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
A note on &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; - this statement is used to ''delete'' a variable/name and after the statement has run, in this case &amp;lt;tt&amp;gt;del a&amp;lt;/tt&amp;gt;, you can no longer access the variable &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; - it is as if it never existed before at all.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;dir()&amp;lt;/tt&amp;gt; function works on ''any'' object. For example, run &amp;lt;tt&amp;gt;dir(print)&amp;lt;/tt&amp;gt; to learn about the attributes of the print function, or &amp;lt;tt&amp;gt;dir(str)&amp;lt;/tt&amp;gt; for the attributes of the str class.&lt;br /&gt;
&lt;br /&gt;
== Packages ==&lt;br /&gt;
&lt;br /&gt;
By now, you must have started observing the hierarchy of organizing your programs. Variables usually go inside functions. Functions and global variables usually go inside modules. What if you wanted to organize modules? That's where packages come into the picture.&lt;br /&gt;
&lt;br /&gt;
Packages are just folders of modules with a special &amp;lt;tt&amp;gt;__init__.py&amp;lt;/tt&amp;gt; file that indicates to Python that this folder is special because it contains Python modules.&lt;br /&gt;
&lt;br /&gt;
Let's say you want to create a package called 'world' with subpackages 'asia', 'africa', etc. and these subpackages in turn contain modules like 'india', 'madagascar', etc.&lt;br /&gt;
&lt;br /&gt;
This is how you would structure the folders:&lt;br /&gt;
&lt;br /&gt;
    - &amp;lt;some folder present in the sys.path&amp;gt;/&lt;br /&gt;
        - world/&lt;br /&gt;
            - __init__.py&lt;br /&gt;
            - asia/&lt;br /&gt;
                - __init__.py&lt;br /&gt;
                - india/&lt;br /&gt;
                    - __init__.py&lt;br /&gt;
                    - foo.py&lt;br /&gt;
            - africa/&lt;br /&gt;
                - __init__.py&lt;br /&gt;
                - madagascar/&lt;br /&gt;
                    - __init__.py&lt;br /&gt;
                    - bar.py&lt;br /&gt;
&lt;br /&gt;
Packages are just a convenience to hierarchically organize modules. You will see many instances of this in the [[Python_en:Standard Library|standard library]].&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Just like functions are reusable parts of programs, modules are reusable programs. Packages are another hierarchy to organize modules. The standard library that comes with Python is an example of such a set of packages and modules.&lt;br /&gt;
&lt;br /&gt;
We have seen how to use these modules and create our own modules.&lt;br /&gt;
&lt;br /&gt;
Next, we will learn about some interesting concepts called data structures.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Functions|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Data Structures|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Modules]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Installation</id>
		<title>Python en:Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Installation"/>
				<updated>2009-02-05T05:23:39Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* For Linux and BSD users */ Note on python3 binary&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have Python 2.x installed already, you do '''not''' have to remove it to install Python 3.0. You can have both installed at the same time.&lt;br /&gt;
&lt;br /&gt;
== For Linux and BSD users ==&lt;br /&gt;
&lt;br /&gt;
If you are using a Linux distribution such as Ubuntu, Fedora, OpenSUSE or {put your choice here}, or a BSD system such as FreeBSD, then it is most likely you already have Python installed on your system.&lt;br /&gt;
&lt;br /&gt;
To test if you have Python already installed on your Linux box, open a shell program (like &amp;lt;tt&amp;gt;konsole&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;gnome-terminal&amp;lt;/tt&amp;gt;) and enter the command &amp;lt;tt&amp;gt;python -V&amp;lt;/tt&amp;gt; as shown below.&lt;br /&gt;
&lt;br /&gt;
    $ python -V&lt;br /&gt;
    Python 3.0b1&lt;br /&gt;
&lt;br /&gt;
; Note&lt;br /&gt;
: &amp;lt;tt&amp;gt;$&amp;lt;/tt&amp;gt; is the prompt of the shell. It will be different for you depending on the settings of your OS, hence I will indicate the prompt by just the &amp;lt;tt&amp;gt;$&amp;lt;/tt&amp;gt; symbol.&lt;br /&gt;
&lt;br /&gt;
If you see some version information like the one shown above, then you have Python installed already.&lt;br /&gt;
&lt;br /&gt;
However, if you get a message like this one:&lt;br /&gt;
&lt;br /&gt;
    $ python -V&lt;br /&gt;
    bash: Python: command not found&lt;br /&gt;
&lt;br /&gt;
Then you don't have Python installed. This is highly unlikely but possible.&lt;br /&gt;
&lt;br /&gt;
; Note&lt;br /&gt;
: If you have Python 2.x already installed, then try &amp;lt;tt&amp;gt;python3 -V&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this case, you have two ways of installing Python on your system.&lt;br /&gt;
&lt;br /&gt;
* You can compile Python from the [http://www.python.org/download/releases/3.0/ source code] and install it. The compilation instructions are provided at the website.&lt;br /&gt;
* [This option will be available after the final release of Python 3.0] Install the binary packages using the package management software that comes with your OS, such as &amp;lt;tt&amp;gt;apt-get&amp;lt;/tt&amp;gt; in Ubuntu/Debian and other Debian-based Linux, &amp;lt;tt&amp;gt;yum&amp;lt;/tt&amp;gt; in Fedora Linux, &amp;lt;tt&amp;gt;pkg_add&amp;lt;/tt&amp;gt; in FreeBSD, etc. Note that you will need an internet connection to use this method. Alternatively, you can download the binaries from somewhere else and then copy to your PC and install it.&lt;br /&gt;
&lt;br /&gt;
== For Windows Users ==&lt;br /&gt;
&lt;br /&gt;
Visit http://www.python.org/download/releases/3.0/ and download the latest version from this website, which was [http://www.python.org/ftp/python/3.0/python-3.0b1.msi 3.0 beta 1] as of this writing. This is just 12.8 MB which is very compact compared to most other languages or software. The installation is just like any other Windows-based software.&lt;br /&gt;
&lt;br /&gt;
; Caution&lt;br /&gt;
: When you are given the option of unchecking any &amp;quot;optional&amp;quot; components, don't uncheck any! Some of these components can be useful for you, especially IDLE.&lt;br /&gt;
&lt;br /&gt;
An interesting fact is that majority of Python downloads are by Windows users. Of course, this doesn't give the complete picture since almost all Linux users will have Python installed already on their systems by default.&lt;br /&gt;
&lt;br /&gt;
=== DOS Prompt ===&lt;br /&gt;
&lt;br /&gt;
If you want to be able to use Python from the Windows command line i.e. the DOS prompt, then you need to set the PATH variable appropriately.&lt;br /&gt;
&lt;br /&gt;
For Windows 2000, XP, 2003 , click on &amp;lt;tt&amp;gt;Control Panel&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;System&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;Advanced&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;Environment Variables&amp;lt;/tt&amp;gt;. Click on the variable named '''PATH''' in the 'System Variables' section, then select &amp;lt;tt&amp;gt;Edit&amp;lt;/tt&amp;gt; and add &amp;lt;tt&amp;gt;;C:\Python30&amp;lt;/tt&amp;gt; to the end of what is already there. Of course, use the appropriate directory name.&lt;br /&gt;
&lt;br /&gt;
For older versions of Windows, add the following line to the file &amp;lt;tt&amp;gt;C:\AUTOEXEC.BAT&amp;lt;/tt&amp;gt; : '&amp;lt;tt&amp;gt;PATH=%PATH%;C:\Python30&amp;lt;/tt&amp;gt;' (without the quotes) and restart the system. For Windows NT, use the &amp;lt;tt&amp;gt;AUTOEXEC.NT&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
== For Mac OS X Users ==&lt;br /&gt;
&lt;br /&gt;
Mac OS X Users will find Python already installed on their system. Open the &amp;lt;tt&amp;gt;Terminal.app&amp;lt;/tt&amp;gt; and run &amp;lt;tt&amp;gt;python -V&amp;lt;/tt&amp;gt; and follow the advice in the above Linux section.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
For a Linux system, you most probably already have Python installed on your system.  Otherwise, you can install it using the package management software that comes with your distribution. For a Windows system, installing Python is as easy as downloading the installer and double-clicking on it. From now on, we will assume that you have Python installed on your system.&lt;br /&gt;
&lt;br /&gt;
Next, we will write our first Python program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Introduction|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:First Steps|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Installation]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Input_Output</id>
		<title>Python en:Input Output</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Input_Output"/>
				<updated>2009-01-25T21:29:54Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* Input from user */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
There will be situations where your program has to interact with the user. For example, you would want to take input from the user and then print some results back. We can achieve this using the &amp;lt;tt&amp;gt;input()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;print()&amp;lt;/tt&amp;gt; functions respectively.&lt;br /&gt;
&lt;br /&gt;
For output, we can also use the various methods of the &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; (string) class. For example, you can use the &amp;lt;tt&amp;gt;rjust&amp;lt;/tt&amp;gt; method to get a string which is right justified to a specified width. See &amp;lt;tt&amp;gt;help(str)&amp;lt;/tt&amp;gt; for more details.&lt;br /&gt;
&lt;br /&gt;
Another common type of input/output is dealing with files. The ability to create, read and write files is essential to many programs and we will explore this aspect in this chapter.&lt;br /&gt;
&lt;br /&gt;
== Input from user ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# user_input.py&lt;br /&gt;
&lt;br /&gt;
def reverse(text):&lt;br /&gt;
    return text[::-1]&lt;br /&gt;
&lt;br /&gt;
def is_palindrome(text):&lt;br /&gt;
    return text == reverse(text)&lt;br /&gt;
&lt;br /&gt;
something = input('Enter text: ')&lt;br /&gt;
if (is_palindrome(something)):&lt;br /&gt;
    print(&amp;quot;Yes, it is a palindrome&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;No, it is not a palindrome&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python user_input.py&lt;br /&gt;
    Enter text: sir&lt;br /&gt;
    No, it is not a palindrome&lt;br /&gt;
    &lt;br /&gt;
    $ python user_input.py&lt;br /&gt;
    Enter text: madam&lt;br /&gt;
    Yes, it is a palindrome&lt;br /&gt;
    &lt;br /&gt;
    $ python user_input.py&lt;br /&gt;
    Enter text: racecar&lt;br /&gt;
    Yes, it is a palindrome&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We use the slicing feature to reverse the text. We've already seen how we can make [[Python_en:Data Structures#Sequences|slices from sequences]] using the &amp;lt;tt&amp;gt;seq[a:b]&amp;lt;/tt&amp;gt; code starting from position &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; to position &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt;. We can also provide a third argument that determines the ''step'' by which the slicing is done. The default step is &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; because of which it returns a continuous part of the text. Giving a negative step, i.e., &amp;lt;tt&amp;gt;-1&amp;lt;/tt&amp;gt; will return the text in reverse.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;input()&amp;lt;/tt&amp;gt; function takes a string as argument and displays it to the user. Then it waits for the user to type something and press the return key. Once the user has entered, the &amp;lt;tt&amp;gt;input()&amp;lt;/tt&amp;gt; function will then return that text.&lt;br /&gt;
&lt;br /&gt;
We take that text and reverse it. If the original text and reversed text are equal, then the text is a [http://en.wiktionary.org/wiki/palindrome palindrome].&lt;br /&gt;
&lt;br /&gt;
Homework exercise:&lt;br /&gt;
&lt;br /&gt;
Checking whether a text is a palindrome should also ignore punctuation, spaces and case. For example, &amp;quot;Rise to vote, sir.&amp;quot; is also a palindrome but our current program doesn't say it is. Can you improve the above program to recognize this palindrome?&lt;br /&gt;
&lt;br /&gt;
== Files ==&lt;br /&gt;
&lt;br /&gt;
You can open and use files for reading or writing by creating an object of the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; class and using its &amp;lt;tt&amp;gt;read&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;readline&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; methods appropriately to read from or write to the file. The ability to read or write to the file depends on the mode you have specified for the file opening. Then finally, when you are finished with the file, you call the &amp;lt;tt&amp;gt;close&amp;lt;/tt&amp;gt; method to tell Python that we are done using the file.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_file.py&lt;br /&gt;
 &lt;br /&gt;
poem = '''\&lt;br /&gt;
Programming is fun&lt;br /&gt;
When the work is done&lt;br /&gt;
if you wanna make your work also fun:&lt;br /&gt;
    use Python!&lt;br /&gt;
'''&lt;br /&gt;
 &lt;br /&gt;
f = open('poem.txt', 'w') # open for 'w'riting&lt;br /&gt;
f.write(poem) # write text to file&lt;br /&gt;
f.close() # close the file&lt;br /&gt;
 &lt;br /&gt;
f = open('poem.txt') # if no mode is specified, 'r'ead mode is assumed by default&lt;br /&gt;
while True:&lt;br /&gt;
    line = f.readline()&lt;br /&gt;
    if len(line) == 0: # Zero length indicates EOF&lt;br /&gt;
        break&lt;br /&gt;
    print(line, end='')&lt;br /&gt;
f.close() # close the file&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_file.py&lt;br /&gt;
    Programming is fun&lt;br /&gt;
    When the work is done&lt;br /&gt;
    if you wanna make your work also fun:&lt;br /&gt;
            use Python!&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
First, open a file by using the built-in &amp;lt;tt&amp;gt;open&amp;lt;/tt&amp;gt; function and specifying the name of the file and the mode in which we want to open the file. The mode can be a read mode (&amp;lt;tt&amp;gt;'r'&amp;lt;/tt&amp;gt;), write mode (&amp;lt;tt&amp;gt;'w'&amp;lt;/tt&amp;gt;) or append mode (&amp;lt;tt&amp;gt;'a'&amp;lt;/tt&amp;gt;). We can also by dealing with a text file (&amp;lt;tt&amp;gt;'t'&amp;lt;/tt&amp;gt;) or a binary file (&amp;lt;tt&amp;gt;'b'&amp;lt;/tt&amp;gt;). There are actually many more modes available and &amp;lt;tt&amp;gt;help(open)&amp;lt;/tt&amp;gt; will give you more details about them. By default, &amp;lt;tt&amp;gt;open()&amp;lt;/tt&amp;gt; considers the file to be a 't'ext file and opens it in 'r'ead mode.&lt;br /&gt;
&lt;br /&gt;
In our example, we first open the file in write text mode and use the &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method of the file object to write to the file and then we finally &amp;lt;tt&amp;gt;close&amp;lt;/tt&amp;gt; the file.&lt;br /&gt;
&lt;br /&gt;
Next, we open the same file again for reading. We don't need to specify a mode because 'read text file' is the default mode. We read in each line of the file using the &amp;lt;tt&amp;gt;readline&amp;lt;/tt&amp;gt; method in a loop. This method returns a complete line including the newline character at the end of the line. When an ''empty'' string is returned, it means that we have reached the end of the file and we 'break' out of the loop.&lt;br /&gt;
&lt;br /&gt;
By deafult, the &amp;lt;tt&amp;gt;print()&amp;lt;/tt&amp;gt; function prints the text as well as an automatic newline to the screen. We are suppressing the newline by specifying &amp;lt;tt&amp;gt;end=&amp;lt;nowiki&amp;gt;''&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; because the line that is read from the file already ends with a newline character. Then, we finally &amp;lt;tt&amp;gt;close&amp;lt;/tt&amp;gt; the file.&lt;br /&gt;
&lt;br /&gt;
Now, check the contents of the &amp;lt;tt&amp;gt;poem.txt&amp;lt;/tt&amp;gt; file to confirm that the program has indeed written and read from that file.&lt;br /&gt;
&lt;br /&gt;
== Pickle ==&lt;br /&gt;
&lt;br /&gt;
Python provides a standard module called &amp;lt;tt&amp;gt;pickle&amp;lt;/tt&amp;gt; using which you can store '''any''' Python object in a file and then get it back later. This is called storing the object ''persistently''.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: pickling.py&lt;br /&gt;
 &lt;br /&gt;
import pickle&lt;br /&gt;
 &lt;br /&gt;
# the name of the file where we will store the object&lt;br /&gt;
shoplistfile = 'shoplist.data'&lt;br /&gt;
# the list of things to buy &lt;br /&gt;
shoplist = ['apple', 'mango', 'carrot']&lt;br /&gt;
 &lt;br /&gt;
# Write to the file&lt;br /&gt;
f = open(shoplistfile, 'wb')&lt;br /&gt;
pickle.dump(shoplist, f) # dump the object to a file&lt;br /&gt;
f.close()&lt;br /&gt;
 &lt;br /&gt;
del shoplist # destroy the shoplist variable&lt;br /&gt;
 &lt;br /&gt;
# Read back from the storage&lt;br /&gt;
f = open(shoplistfile, 'rb')&lt;br /&gt;
storedlist = pickle.load(f) # load the object from the file&lt;br /&gt;
print(storedlist)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python pickling.py&lt;br /&gt;
    ['apple', 'mango', 'carrot']&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
To store an object in a file, we have to first &amp;lt;tt&amp;gt;open&amp;lt;/tt&amp;gt; the file in 'w'rite 'b'inary mode and then call the &amp;lt;tt&amp;gt;dump&amp;lt;/tt&amp;gt; function of the &amp;lt;tt&amp;gt;pickle&amp;lt;/tt&amp;gt; module. This process is called ''pickling''.&lt;br /&gt;
&lt;br /&gt;
Next, we retrieve the object using the &amp;lt;tt&amp;gt;load&amp;lt;/tt&amp;gt; function of the &amp;lt;tt&amp;gt;pickle&amp;lt;/tt&amp;gt; module which returns the object. This process is called ''unpickling''.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have discussed various types of input/output and also file handling and using the pickle module.&lt;br /&gt;
&lt;br /&gt;
Next, we will explore the concept of exceptions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Object Oriented Programming|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Exceptions|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Input Output]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Data_Structures</id>
		<title>Python en:Data Structures</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Data_Structures"/>
				<updated>2009-01-25T21:28:58Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Data structures are basically just that - they are ''structures'' which can hold some ''data'' together. In other words, they are used to store a collection of related data.&lt;br /&gt;
&lt;br /&gt;
There are four built-in data structures in Python - list, tuple, dictionary and set. We will see how to use each of them and how they make life easier for us.&lt;br /&gt;
&lt;br /&gt;
== List ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;list&amp;lt;/tt&amp;gt; is a data structure that holds an ordered collection of items i.e. you can store a ''sequence'' of items in a list. This is easy to imagine if you can think of a shopping list where you have a list of items to buy, except that you probably have each item on a separate line in your shopping list whereas in Python you put commas in between them.&lt;br /&gt;
&lt;br /&gt;
The list of items should be enclosed in square brackets so that Python understands that you are specifying a list. Once you have created a list, you can add, remove or search for items in the list. Since we can add and remove items, we say that a list is a ''mutable'' data type i.e. this type can be altered.&lt;br /&gt;
&lt;br /&gt;
=== Quick Introduction To Objects And Classes ===&lt;br /&gt;
&lt;br /&gt;
Although I've been generally delaying the discussion of objects and classes till now, a little explanation is needed right now so that you can understand lists better. We will explore this topic in detail later in its [[Python_en:Object Oriented Programming|own chapter]].&lt;br /&gt;
&lt;br /&gt;
A list is an example of usage of objects and classes. When we use a variable &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; and assign a value to it, say integer &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; to it, you can think of it as creating an '''object''' (i.e. instance) &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; of '''class''' (i.e. type) &amp;lt;tt&amp;gt;int&amp;lt;/tt&amp;gt;. In fact, you can read &amp;lt;tt&amp;gt;help(int)&amp;lt;/tt&amp;gt; to understand this better.&lt;br /&gt;
&lt;br /&gt;
A class can also have '''methods''' i.e. functions defined for use with respect to that class only. You can use these pieces of functionality only when you have an object of that class. For example, Python provides an &amp;lt;tt&amp;gt;append&amp;lt;/tt&amp;gt; method for the &amp;lt;tt&amp;gt;list&amp;lt;/tt&amp;gt; class which allows you to add an item to the end of the list. For example, &amp;lt;tt&amp;gt;mylist.append('an item')&amp;lt;/tt&amp;gt; will add that string to the list &amp;lt;tt&amp;gt;mylist&amp;lt;/tt&amp;gt;. Note the use of dotted notation for accessing methods of the objects.&lt;br /&gt;
&lt;br /&gt;
A class can also have '''fields''' which are nothing but variables defined for use with respect to that class only. You can use these variables/names only when you have an object of that class. Fields are also accessed by the dotted notation, for example, &amp;lt;tt&amp;gt;mylist.field&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_list.py&lt;br /&gt;
&lt;br /&gt;
# This is my shopping list&lt;br /&gt;
shoplist = ['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
&lt;br /&gt;
print('I have', len(shoplist), 'items to purchase.')&lt;br /&gt;
&lt;br /&gt;
print('These items are:', end=' ')&lt;br /&gt;
for item in shoplist:&lt;br /&gt;
    print(item, end=' ')&lt;br /&gt;
&lt;br /&gt;
print('\nI also have to buy rice.')&lt;br /&gt;
shoplist.append('rice')&lt;br /&gt;
print('My shopping list is now', shoplist)&lt;br /&gt;
&lt;br /&gt;
print('I will sort my list now')&lt;br /&gt;
shoplist.sort()&lt;br /&gt;
print('Sorted shopping list is', shoplist)&lt;br /&gt;
&lt;br /&gt;
print('The first item I will buy is', shoplist[0])&lt;br /&gt;
olditem = shoplist[0]&lt;br /&gt;
del shoplist[0]&lt;br /&gt;
print('I bought the', olditem)&lt;br /&gt;
print('My shopping list is now', shoplist)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_list.py&lt;br /&gt;
    I have 4 items to purchase.&lt;br /&gt;
    These items are: apple mango carrot banana&lt;br /&gt;
    I also have to buy rice.&lt;br /&gt;
    My shopping list is now ['apple', 'mango', 'carrot', 'banana', 'rice']&lt;br /&gt;
    I will sort my list now&lt;br /&gt;
    Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice']&lt;br /&gt;
    The first item I will buy is apple&lt;br /&gt;
    I bought the apple&lt;br /&gt;
    My shopping list is now ['banana', 'carrot', 'mango', 'rice']&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;tt&amp;gt;shoplist&amp;lt;/tt&amp;gt; is a shopping list for someone who is going to the market. In &amp;lt;tt&amp;gt;shoplist&amp;lt;/tt&amp;gt;, we only store strings of the names of the items to buy but you can add ''any kind of object'' to a list including numbers and even other lists.&lt;br /&gt;
&lt;br /&gt;
We have also used the &amp;lt;tt&amp;gt;for..in&amp;lt;/tt&amp;gt; loop to iterate through the items of the list. By now, you must have realised that a list is also a sequence. The speciality of sequences will be discussed in a later [[#Sequences|section]].&lt;br /&gt;
&lt;br /&gt;
Notice the use of the &amp;lt;tt&amp;gt;end&amp;lt;/tt&amp;gt; keyword argument to the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; function to indicate that we want to end the output with a space instead of the usual line break.&lt;br /&gt;
&lt;br /&gt;
Next, we add an item to the list using the &amp;lt;tt&amp;gt;append&amp;lt;/tt&amp;gt; method of the list object, as already discussed before. Then, we check that the item has been indeed added to the list by printing the contents of the list by simply passing the list to the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; statement which prints it neatly.&lt;br /&gt;
&lt;br /&gt;
Then, we sort the list by using the &amp;lt;tt&amp;gt;sort&amp;lt;/tt&amp;gt; method of the list. It is important to understand that this method affects the list itself and does not return a modified list - this is different from the way strings work. This is what we mean by saying that lists are ''mutable'' and that strings are ''immutable''.&lt;br /&gt;
&lt;br /&gt;
Next, when we finish buying an item in the market, we want to remove it from the list. We achieve this by using the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; statement. Here, we mention which item of the list we want to remove and the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; statement removes it from the list for us.  We specify that we want to remove the first item from the list and hence we use &amp;lt;tt&amp;gt;del shoplist[0]&amp;lt;/tt&amp;gt; (remember that Python starts counting from 0).&lt;br /&gt;
&lt;br /&gt;
If you want to know all the methods defined by the list object, see &amp;lt;tt&amp;gt;help(list)&amp;lt;/tt&amp;gt; for details.&lt;br /&gt;
&lt;br /&gt;
== Tuple ==&lt;br /&gt;
&lt;br /&gt;
Tuples are used to hold together multiple objects. Think of them as similar to lists, but without the extensive functionality that the list class gives you. One major feature of tuples is that they are '''immutable''' like strings i.e. you cannot modify tuples.&lt;br /&gt;
&lt;br /&gt;
Tuples are defined by specifying items separated by commas within an optional pair of parentheses.&lt;br /&gt;
&lt;br /&gt;
Tuples are usually used in cases where a statement or a user-defined function can safely assume that the collection of values i.e. the tuple of values used will not change.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_tuple.py&lt;br /&gt;
&lt;br /&gt;
zoo = ('python', 'elephant', 'penguin') # remember the parentheses are optional&lt;br /&gt;
print('Number of animals in the zoo is', len(zoo))&lt;br /&gt;
&lt;br /&gt;
new_zoo = ('monkey', 'camel', zoo)&lt;br /&gt;
print('Number of cages in the new zoo is', len(new_zoo))&lt;br /&gt;
print('All animals in new zoo are', new_zoo)&lt;br /&gt;
print('Animals brought from old zoo are', new_zoo[2])&lt;br /&gt;
print('Last animal brought from old zoo is', new_zoo[2][2])&lt;br /&gt;
print('Number of animals in the new zoo is', len(new_zoo)-1+len(new_zoo[2]))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_tuple.py&lt;br /&gt;
    Number of animals in the zoo is 3&lt;br /&gt;
    Number of cages in the new zoo is 3&lt;br /&gt;
    All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin'))&lt;br /&gt;
    Animals brought from old zoo are ('python', 'elephant', 'penguin')&lt;br /&gt;
    Last animal brought from old zoo is penguin&lt;br /&gt;
    Number of animals in the new zoo is 5&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;tt&amp;gt;zoo&amp;lt;/tt&amp;gt; refers to a tuple of items. We see that the &amp;lt;tt&amp;gt;len&amp;lt;/tt&amp;gt; function can be used to get the length of the tuple. This also indicates that a tuple is a [[#Sequences|sequence]] as well.&lt;br /&gt;
&lt;br /&gt;
We are now shifting these animals to a new zoo since the old zoo is being closed. Therefore, the &amp;lt;tt&amp;gt;new_zoo&amp;lt;/tt&amp;gt; tuple contains some animals which are already there along with the animals brought over from the old zoo. Back to reality, note that a tuple within a tuple does not lose its identity.&lt;br /&gt;
&lt;br /&gt;
We can access the items in the tuple by specifying the item's position within a pair of square brackets just like we did for lists. This is called the ''indexing'' operator. We access the third item in &amp;lt;tt&amp;gt;new_zoo&amp;lt;/tt&amp;gt; by specifying &amp;lt;tt&amp;gt;new_zoo[2]&amp;lt;/tt&amp;gt; and we access the third item within the third item in the &amp;lt;tt&amp;gt;new_zoo&amp;lt;/tt&amp;gt; tuple by specifying &amp;lt;tt&amp;gt;new_zoo[2][2]&amp;lt;/tt&amp;gt;. This is pretty simple once you've understood the idiom.&lt;br /&gt;
&lt;br /&gt;
; Parentheses&lt;br /&gt;
: Although the parentheses is optional, I prefer always having them to make it obvious that it is a tuple, especially because it avoids ambiguity. For example, &amp;lt;tt&amp;gt;print(1,2,3)&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;print( (1,2,3) )&amp;lt;/tt&amp;gt; mean two different things - the former prints three numbers whereas the latter prints a tuple (which contains three numbers).&lt;br /&gt;
&lt;br /&gt;
; Tuple with 0 or 1 items&lt;br /&gt;
: An empty tuple is constructed by an empty pair of parentheses such as &amp;lt;tt&amp;gt;myempty = ()&amp;lt;/tt&amp;gt;. However, a tuple with a single item is not so simple. You have to specify it using a comma following the first (and only) item so that Python can differentiate between a tuple and a pair of parentheses surrounding the object in an expression i.e. you have to specify &amp;lt;tt&amp;gt;singleton = (2 , )&amp;lt;/tt&amp;gt; if you mean you want a tuple containing the item &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; Note for Perl programmers&lt;br /&gt;
: A list within a list does not lose its identity i.e. lists are not flattened as in Perl. The same applies to a tuple within a tuple, or a tuple within a list, or a list within a tuple, etc. As far as Python is concerned, they are just objects stored using another object, that's all.&lt;br /&gt;
&lt;br /&gt;
== Dictionary ==&lt;br /&gt;
&lt;br /&gt;
A dictionary is like an address-book where you can find the address or contact details of a person by knowing only his/her name i.e. we associate '''keys''' (name) with '''values''' (details). Note that the key must be unique just like you cannot find out the correct information if you have two persons with the exact same name.&lt;br /&gt;
&lt;br /&gt;
Note that you can use only immutable objects (like strings) for the keys of a dictionary but you can use either immutable or mutable objects for the values of the dictionary.  This basically translates to say that you should use only simple objects for keys.&lt;br /&gt;
&lt;br /&gt;
Pairs of keys and values are specified in a dictionary by using the notation &amp;lt;tt&amp;gt;d = {key1 : value1, key2 : value2 }&amp;lt;/tt&amp;gt;. Notice that the key-value pairs are separated by a colon and the pairs are separated themselves by commas and all this is enclosed in a pair of curly braces.&lt;br /&gt;
&lt;br /&gt;
Remember that key-value pairs in a dictionary are not ordered in any manner. If you want a particular order, then you will have to sort them yourself before using it.&lt;br /&gt;
&lt;br /&gt;
The dictionaries that you will be using are instances/objects of the &amp;lt;tt&amp;gt;dict&amp;lt;/tt&amp;gt; class.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_dict.py&lt;br /&gt;
&lt;br /&gt;
# 'ab' is short for 'a'ddress'b'ook&lt;br /&gt;
&lt;br /&gt;
ab = {  'Swaroop'   : 'swaroop@swaroopch.com',&lt;br /&gt;
        'Larry'     : 'larry@wall.org',&lt;br /&gt;
        'Matsumoto' : 'matz@ruby-lang.org',&lt;br /&gt;
        'Spammer'   : 'spammer@hotmail.com'&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;Swaroop's address is&amp;quot;, ab['Swaroop'])&lt;br /&gt;
&lt;br /&gt;
# Deleting a key-value pair&lt;br /&gt;
del ab['Spammer']&lt;br /&gt;
&lt;br /&gt;
print('\nThere are {0} contacts in the address-book\n'.format(len(ab)))&lt;br /&gt;
&lt;br /&gt;
for name, address in ab.items():&lt;br /&gt;
    print('Contact {0} at {1}'.format(name, address))&lt;br /&gt;
&lt;br /&gt;
# Adding a key-value pair&lt;br /&gt;
ab['Guido'] = 'guido@python.org'&lt;br /&gt;
&lt;br /&gt;
if 'Guido' in ab: # OR ab.has_key('Guido')&lt;br /&gt;
    print(&amp;quot;\nGuido's address is&amp;quot;, ab['Guido'])&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python using_dict.py&lt;br /&gt;
    Swaroop's address is swaroop@swaroopch.com&lt;br /&gt;
    &lt;br /&gt;
    There are 3 contacts in the address-book&lt;br /&gt;
    &lt;br /&gt;
    Contact Swaroop at swaroop@swaroopch.com&lt;br /&gt;
    Contact Matsumoto at matz@ruby-lang.org&lt;br /&gt;
    Contact Larry at larry@wall.org&lt;br /&gt;
    &lt;br /&gt;
    Guido's address is guido@python.org&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We create the dictionary &amp;lt;tt&amp;gt;ab&amp;lt;/tt&amp;gt; using the notation already discussed. We then access key-value pairs by specifying the key using the indexing operator as discussed in the context of lists and tuples. Observe the simple syntax.&lt;br /&gt;
&lt;br /&gt;
We can delete key-value pairs using our old friend - the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; statement. We simply specify the dictionary and the indexing operator for the key to be removed and pass it to the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; statement. There is no need to know the value corresponding to the key for this operation.&lt;br /&gt;
&lt;br /&gt;
Next, we access each key-value pair of the dictionary using the &amp;lt;tt&amp;gt;items&amp;lt;/tt&amp;gt; method of the dictionary which returns a list of tuples where each tuple contains a pair of items - the key followed by the value. We retrieve this pair and assign it to the variables &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;address&amp;lt;/tt&amp;gt; correspondingly for each pair using the &amp;lt;tt&amp;gt;for..in&amp;lt;/tt&amp;gt; loop and then print these values in the for-block.&lt;br /&gt;
&lt;br /&gt;
We can add new key-value pairs by simply using the indexing operator to access a key and assign that value, as we have done for Guido in the above case.&lt;br /&gt;
&lt;br /&gt;
We can check if a key-value pair exists using the &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt; operator or even the &amp;lt;tt&amp;gt;has_key&amp;lt;/tt&amp;gt; method of the &amp;lt;tt&amp;gt;dict&amp;lt;/tt&amp;gt; class. You can see the documentation for the complete list of methods of the &amp;lt;tt&amp;gt;dict&amp;lt;/tt&amp;gt; class using &amp;lt;tt&amp;gt;help(dict)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; Keyword Arguments and Dictionaries&lt;br /&gt;
: On a different note, if you have used keyword arguments in your functions, you have already used dictionaries! Just think about it - the key-value pair is specified by you in the parameter list of the function definition and when you access variables within your function, it is just a key access of a dictionary (which is called the ''symbol table'' in compiler design terminology).&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
Lists, tuples and strings are examples of sequences, but what are sequences and what is so special about them?&lt;br /&gt;
&lt;br /&gt;
The major features is that they have membership tests (i.e. the &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;not in&amp;lt;/tt&amp;gt; expressions) and indexing operations. The '''indexing''' operation which allows us to fetch a particular item in the sequence directly.&lt;br /&gt;
&lt;br /&gt;
The three types of sequences mentioned above - lists, tuples and strings, also have a '''slicing''' operation which allows us to retrieve a slice of the sequence i.e. a part of the sequence.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: seq.py&lt;br /&gt;
&lt;br /&gt;
shoplist = ['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
name = 'swaroop'&lt;br /&gt;
&lt;br /&gt;
# Indexing or 'Subscription' operation&lt;br /&gt;
print('Item 0 is', shoplist[0])&lt;br /&gt;
print('Item 1 is', shoplist[1])&lt;br /&gt;
print('Item 2 is', shoplist[2])&lt;br /&gt;
print('Item 3 is', shoplist[3])&lt;br /&gt;
print('Item -1 is', shoplist[-1])&lt;br /&gt;
print('Item -2 is', shoplist[-2])&lt;br /&gt;
print('Character 0 is', name[0])&lt;br /&gt;
&lt;br /&gt;
# Slicing on a list&lt;br /&gt;
print('Item 1 to 3 is', shoplist[1:3])&lt;br /&gt;
print('Item 2 to end is', shoplist[2:])&lt;br /&gt;
print('Item 1 to -1 is', shoplist[1:-1])&lt;br /&gt;
print('Item start to end is', shoplist[:])&lt;br /&gt;
&lt;br /&gt;
# Slicing on a string&lt;br /&gt;
print('characters 1 to 3 is', name[1:3])&lt;br /&gt;
print('characters 2 to end is', name[2:])&lt;br /&gt;
print('characters 1 to -1 is', name[1:-1])&lt;br /&gt;
print('characters start to end is', name[:])&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python seq.py&lt;br /&gt;
    Item 0 is apple&lt;br /&gt;
    Item 1 is mango&lt;br /&gt;
    Item 2 is carrot&lt;br /&gt;
    Item 3 is banana&lt;br /&gt;
    Item -1 is banana&lt;br /&gt;
    Item -2 is carrot&lt;br /&gt;
    Character 0 is s&lt;br /&gt;
    Item 1 to 3 is ['mango', 'carrot']&lt;br /&gt;
    Item 2 to end is ['carrot', 'banana']&lt;br /&gt;
    Item 1 to -1 is ['mango', 'carrot']&lt;br /&gt;
    Item start to end is ['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
    characters 1 to 3 is wa&lt;br /&gt;
    characters 2 to end is aroop&lt;br /&gt;
    characters 1 to -1 is waroo&lt;br /&gt;
    characters start to end is swaroop&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
First, we see how to use indexes to get individual items of a sequence. This is also referred to as the ''subscription operation''. Whenever you specify a number to a sequence within square brackets as shown above, Python will fetch you the item corresponding to that position in the sequence. Remember that Python starts counting numbers from 0. Hence, &amp;lt;tt&amp;gt;shoplist[0]&amp;lt;/tt&amp;gt; fetches the first item and &amp;lt;tt&amp;gt;shoplist[3]&amp;lt;/tt&amp;gt; fetches the fourth item in the &amp;lt;tt&amp;gt;shoplist&amp;lt;/tt&amp;gt; sequence.&lt;br /&gt;
&lt;br /&gt;
The index can also be a negative number, in which case, the position is calculated from the end of the sequence. Therefore, &amp;lt;tt&amp;gt;shoplist[-1]&amp;lt;/tt&amp;gt; refers to the last item in the sequence and &amp;lt;tt&amp;gt;shoplist[-2]&amp;lt;/tt&amp;gt; fetches the second last item in the sequence.&lt;br /&gt;
&lt;br /&gt;
The slicing operation is used by specifying the name of the sequence followed by an optional pair of numbers separated by a colon within square brackets. Note that this is very similar to the indexing operation you have been using till now. Remember the numbers are optional but the colon isn't.&lt;br /&gt;
&lt;br /&gt;
The first number (before the colon) in the slicing operation refers to the position from where the slice starts and the second number (after the colon) indicates where the slice will stop at. If the first number is not specified, Python will start at the beginning of the sequence. If the second number is left out, Python will stop at the end of the sequence. Note that the slice returned ''starts'' at the start position and will end just before the ''end'' position i.e. the start position is included but the end position is excluded from the sequence slice.&lt;br /&gt;
&lt;br /&gt;
Thus, &amp;lt;tt&amp;gt;shoplist[1:3]&amp;lt;/tt&amp;gt; returns a slice of the sequence starting at position 1, includes position 2 but stops at position 3 and therefore a ''slice'' of two items is returned.  Similarly, &amp;lt;tt&amp;gt;shoplist[:]&amp;lt;/tt&amp;gt; returns a copy of the whole sequence.&lt;br /&gt;
&lt;br /&gt;
You can also do slicing with negative positions. Negative numbers are used for positions from the end of the sequence. For example, &amp;lt;tt&amp;gt;shoplist[:-1]&amp;lt;/tt&amp;gt; will return a slice of the sequence which excludes the last item of the sequence but contains everything else.&lt;br /&gt;
&lt;br /&gt;
You can also provide a third argument for the slice, which is the ''step'' for the slicing (by default, the step size is 1):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; shoplist = ['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; shoplist[::1]&lt;br /&gt;
['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; shoplist[::2]&lt;br /&gt;
['apple', 'carrot']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; shoplist[::3]&lt;br /&gt;
['apple', 'banana']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; shoplist[::-1]&lt;br /&gt;
['banana', 'carrot', 'mango', 'apple']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that when the step is 2, we get the items with position 0, 2, ... When the step size is 3, we get the items with position 0, 3, etc.&lt;br /&gt;
&lt;br /&gt;
Try various combinations of such slice specifications using the Python interpreter interactively i.e. the prompt so that you can see the results immediately. The great thing about sequences is that you can access tuples, lists and strings all in the same way!&lt;br /&gt;
&lt;br /&gt;
== Set ==&lt;br /&gt;
&lt;br /&gt;
Sets are ''unordered'' collections of simple objects. These are used when the existence of an object in a collection is more important than the order or how many times it occurs.&lt;br /&gt;
&lt;br /&gt;
Using sets, you can test for membership, whether it is a subset of another set, find the intersection between two sets, and so on.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bri = set(['brazil', 'russia', 'india'])&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 'india' in bri&lt;br /&gt;
True&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 'usa' in bri&lt;br /&gt;
False&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bric = bri.copy()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bric.add('china')&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bric.issuperset(bri)&lt;br /&gt;
True&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bri.remove('russia')&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bri &amp;amp; bric # OR bri.intersection(bric)&lt;br /&gt;
{'brazil', 'india'}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The example is pretty much self-explanatory because it involves basic set theory mathematics taught in school.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
When you create an object and assign it to a variable, the variable only ''refers'' to the object and does not represent the object itself! That is, the variable name points to that part of your computer's memory where the object is stored. This is called as '''binding''' of the name to the object.&lt;br /&gt;
&lt;br /&gt;
Generally, you don't need to be worried about this, but there is a subtle effect due to references which you need to be aware of:&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: reference.py&lt;br /&gt;
&lt;br /&gt;
print('Simple Assignment')&lt;br /&gt;
shoplist = ['apple', 'mango', 'carrot', 'banana']&lt;br /&gt;
mylist = shoplist # mylist is just another name pointing to the same object!&lt;br /&gt;
&lt;br /&gt;
del shoplist[0] # I purchased the first item, so I remove it from the list&lt;br /&gt;
&lt;br /&gt;
print('shoplist is', shoplist)&lt;br /&gt;
print('mylist is', mylist)&lt;br /&gt;
# notice that both shoplist and mylist both print the same list without&lt;br /&gt;
# the 'apple' confirming that they point to the same object&lt;br /&gt;
&lt;br /&gt;
print('Copy by making a full slice')&lt;br /&gt;
mylist = shoplist[:] # make a copy by doing a full slice&lt;br /&gt;
del mylist[0] # remove first item&lt;br /&gt;
&lt;br /&gt;
print('shoplist is', shoplist)&lt;br /&gt;
print('mylist is', mylist)&lt;br /&gt;
# notice that now the two lists are different&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python reference.py&lt;br /&gt;
    Simple Assignment&lt;br /&gt;
    shoplist is ['mango', 'carrot', 'banana']&lt;br /&gt;
    mylist is ['mango', 'carrot', 'banana']&lt;br /&gt;
    Copy by making a full slice&lt;br /&gt;
    shoplist is ['mango', 'carrot', 'banana']&lt;br /&gt;
    mylist is ['carrot', 'banana']&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Most of the explanation is available in the comments.&lt;br /&gt;
&lt;br /&gt;
Remember that if you want to make a copy of a list or such kinds of sequences or complex objects (not simple ''objects'' such as integers), then you have to use the slicing operation to make a copy. If you just assign the variable name to another name, both of them will ''refer'' to the same object and this could be trouble if you are not careful.&lt;br /&gt;
&lt;br /&gt;
; Note for Perl programmers&lt;br /&gt;
: Remember that an assignment statement for lists does '''not''' create a copy. You have to use slicing operation to make a copy of the sequence.&lt;br /&gt;
&lt;br /&gt;
== More About Strings ==&lt;br /&gt;
&lt;br /&gt;
We have already discussed strings in detail earlier. What more can there be to know?  Well, did you know that strings are also objects and have methods which do everything from checking part of a string to stripping spaces!&lt;br /&gt;
&lt;br /&gt;
The strings that you use in program are all objects of the class &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt;.  Some useful methods of this class are demonstrated in the next example. For a complete list of such methods, see &amp;lt;tt&amp;gt;help(str)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: str_methods.py&lt;br /&gt;
&lt;br /&gt;
name = 'Swaroop' # This is a string object&lt;br /&gt;
&lt;br /&gt;
if name.startswith('Swa'):&lt;br /&gt;
    print('Yes, the string starts with &amp;quot;Swa&amp;quot;')&lt;br /&gt;
&lt;br /&gt;
if 'a' in name:&lt;br /&gt;
    print('Yes, it contains the string &amp;quot;a&amp;quot;')&lt;br /&gt;
&lt;br /&gt;
if name.find('war') != -1:&lt;br /&gt;
    print('Yes, it contains the string &amp;quot;war&amp;quot;')&lt;br /&gt;
&lt;br /&gt;
delimiter = '_*_'&lt;br /&gt;
mylist = ['Brazil', 'Russia', 'India', 'China']&lt;br /&gt;
print(delimiter.join(mylist))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python str_methods.py&lt;br /&gt;
    Yes, the string starts with &amp;quot;Swa&amp;quot;&lt;br /&gt;
    Yes, it contains the string &amp;quot;a&amp;quot;&lt;br /&gt;
    Yes, it contains the string &amp;quot;war&amp;quot;&lt;br /&gt;
    Brazil_*_Russia_*_India_*_China&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Here, we see a lot of the string methods in action. The &amp;lt;tt&amp;gt;startswith&amp;lt;/tt&amp;gt; method is used to find out whether the string starts with the given string. The &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt; operator is used to check if a given string is a part of the string.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;find&amp;lt;/tt&amp;gt; method is used to do find the position of the given string in the string or returns -1 if it is not successful to find the substring. The &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; class also has a neat method to &amp;lt;tt&amp;gt;join&amp;lt;/tt&amp;gt; the items of a sequence with the string acting as a delimiter between each item of the sequence and returns a bigger string generated from this.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have explored the various built-in data structures of Python in detail. These data structures will be essential for writing programs of reasonable size.&lt;br /&gt;
&lt;br /&gt;
Now that we have a lot of the basics of Python in place, we will next see how to design and write a real-world Python program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Modules|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Problem Solving|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Data Structures]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Appendix_FLOSS</id>
		<title>Python en:Appendix FLOSS</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Appendix_FLOSS"/>
				<updated>2009-01-25T21:21:27Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;Apparently the e is not accented, correction by Tarek&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Free/Libre and Open Source Software (FLOSS) ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/FLOSS FLOSS] is based on the concept of a community, which itself is based on the concept of sharing, and particularly the sharing of knowledge. FLOSS are free for usage, modification and redistribution.&lt;br /&gt;
&lt;br /&gt;
If you have already read this book, then you are already familiar with FLOSS since you have been using '''Python''' all along and Python is an open source software!&lt;br /&gt;
&lt;br /&gt;
Here are some examples of FLOSS to give an idea of the kind of things that community sharing and building can create:&lt;br /&gt;
&lt;br /&gt;
* '''Linux'''. This is a FLOSS operating system that the whole world is slowly embracing! It was started by Linus Torvalds as a student. Now, it is giving competition to Microsoft Windows. [&amp;amp;nbsp;[http://www.kernel.org Linux Kernel]&amp;amp;nbsp;]&lt;br /&gt;
* '''Ubuntu'''. This is a community-driven distribution, sponsored by Canonical and it is the most popular Linux distribution today. It allows you to install a plethora of FLOSS available and all this in an easy-to-use and easy-to-install manner. Best of all, you can just reboot your computer and run Linux off the CD! This allows you to completely try out the new OS before installing it on your computer. [&amp;amp;nbsp;[http://www.ubuntu.com Ubuntu Linux]&amp;amp;nbsp;]&lt;br /&gt;
* '''OpenOffice.org'''. This is an excellent office suite with a writer, presentation, spreadsheet and drawing components among other things. It can even open and edit MS Word and MS PowerPoint files with ease. It runs on almost all platforms. [&amp;amp;nbsp;[http://www.openoffice.org OpenOffice]&amp;amp;nbsp;]&lt;br /&gt;
* '''Mozilla Firefox'''. This is ''the'' next generation web browser which is giving great competition to Internet Explorer. It is blazingly fast and has gained critical acclaim for its sensible and impressive features. The extensions concept allows any kind of plugins to be used.&lt;br /&gt;
* Its companion product Thunderbird is an excellent email client that makes reading email a snap. [&amp;amp;nbsp;[http://www.mozilla.org/products/firefox Mozilla Firefox], [http://www.mozilla.org/products/thunderbird Mozilla Thunderbird]&amp;amp;nbsp;]&lt;br /&gt;
* '''Mono'''.  This is an open source implementation of the Microsoft .NET platform.  It allows .NET applications to be created and run on Linux, Windows, FreeBSD, Mac OS and many other platforms as well. [&amp;amp;nbsp;[http://www.mono-project.com Mono], [http://www.ecma-international.org ECMA], [http://www.microsoft.com/net Microsoft .NET]&amp;amp;nbsp;]&lt;br /&gt;
* '''Apache web server'''. This is the popular open source web server. In fact, it is ''the'' most popular web server on the planet! It runs nearly more than half of the websites out there. Yes, that's right - Apache handles more websites than all the competition (including Microsoft IIS) combined. [&amp;amp;nbsp;[http://httpd.apache.org Apache]&amp;amp;nbsp;]&lt;br /&gt;
* '''MySQL'''. This is an extremely popular open source database server. It is most famous for it's blazing speed. It is the M in the famous LAMP stack which runs most of the websites on the internet. [&amp;amp;nbsp;[http://www.mysql.com MySQL]&amp;amp;nbsp;]&lt;br /&gt;
* '''VLC Player'''. This is a video player that can play anything from DivX to MP3 to Ogg to VCDs and DVDs to ... who says open source ain't fun? ;-) [&amp;amp;nbsp;[http://www.videolan.org/vlc/ VLC media player]&amp;amp;nbsp;]&lt;br /&gt;
* '''GeexBox''' is a Linux distribution that is designed to play movies as soon as you boot up from the CD! [&amp;amp;nbsp;[http://geexbox.org/en/start.html GeexBox]&amp;amp;nbsp;]&lt;br /&gt;
&lt;br /&gt;
This list is just intended to give you a brief idea - there are many more excellent FLOSS out there, such as the Perl language, PHP language, Drupal content management system for websites, PostgreSQL database server, TORCS racing game, KDevelop IDE, Xine - the movie player, VIM editor, Quanta+ editor, Banshee audio player, GIMP image editing program, ... This list could go on forever.&lt;br /&gt;
&lt;br /&gt;
To get the latest buzz in the FLOSS world, check out the following websites:&lt;br /&gt;
&lt;br /&gt;
* [http://www.linux.com linux.com]&lt;br /&gt;
* [http://www.linuxtoday.com LinuxToday]&lt;br /&gt;
* [http://www.newsforge.com NewsForge]&lt;br /&gt;
* [http://www.distrowatch.com DistroWatch]&lt;br /&gt;
&lt;br /&gt;
Visit the following websites for more information on FLOSS:&lt;br /&gt;
&lt;br /&gt;
* [http://www.sourceforge.net SourceForge]&lt;br /&gt;
* [http://www.freshmeat.net FreshMeat]&lt;br /&gt;
&lt;br /&gt;
So, go ahead and explore the vast, free and open world of FLOSS!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:What Next|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Appendix About|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Appendix FLOSS]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Operators_and_Expressions</id>
		<title>Python en:Operators and Expressions</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Operators_and_Expressions"/>
				<updated>2009-01-25T21:19:20Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* Expressions */ Fixing typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Most statements (logical lines) that you write will contain '''expressions'''. A simple example of an expression is &amp;lt;tt&amp;gt;2 + 3&amp;lt;/tt&amp;gt;. An expression can be broken down into operators and operands.&lt;br /&gt;
&lt;br /&gt;
''Operators'' are functionality that do something and can be represented by symbols such as &amp;lt;tt&amp;gt;+&amp;lt;/tt&amp;gt; or by special keywords. Operators require some data to operate on and such data is called ''operands''. In this case, &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; are the operands.&lt;br /&gt;
&lt;br /&gt;
== Operators ==&lt;br /&gt;
&lt;br /&gt;
We will briefly take a look at the operators and their usage:&lt;br /&gt;
&lt;br /&gt;
Note that you can evaluate the expressions given in the examples using the interpreter interactively. For example, to test the expression &amp;lt;tt&amp;gt;2 + 3&amp;lt;/tt&amp;gt;, use the interactive Python interpreter prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 2 + 3&lt;br /&gt;
5&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 3 * 5&lt;br /&gt;
15&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;caption&amp;gt;Operators And Their Usage&amp;lt;/caption&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Operator&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Name&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Explanation&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Examples&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
+&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Plus&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Adds the two objects&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;3 + 5&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;8&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;'a' + 'b'&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;'ab'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
-&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Minus&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Either gives a negative number or gives the subtraction of one number from the other&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;-5.2&amp;lt;/tt&amp;gt; gives a negative number. &amp;lt;tt&amp;gt;50 - 24&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;26&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Multiply&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Gives the multiplication of the two numbers or returns the string repeated that many times.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;2 * 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;6&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;'la' * 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;'lalala'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Power&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns x to the power of y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;3 ** 4&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;81&amp;lt;/tt&amp;gt; (i.e. &amp;lt;tt&amp;gt;3 * 3 * 3 * 3&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Divide&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Divide x by y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;4 / 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;1.3333333333333333&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
//&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Floor Division&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Returns the floor of the quotient&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;4 // 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
%&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Modulo&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Returns the remainder of the division&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;8 % 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;-25.5 % 2.25&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;1.5&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;lt;&amp;amp;lt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Left Shift&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Shifts the bits of the number to the left by the number of bits specified. (Each number is represented in memory by bits or binary digits i.e. 0 and 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;2 &amp;amp;lt;&amp;amp;lt; 2&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;8&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; is represented by &amp;lt;tt&amp;gt;10&amp;lt;/tt&amp;gt; in bits. Left shifting by 2 bits gives &amp;lt;tt&amp;gt;1000&amp;lt;/tt&amp;gt; which represents the decimal &amp;lt;tt&amp;gt;8&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;gt;&amp;amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Right Shift&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Shifts the bits of the number to the right by the number of bits specified.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;11 &amp;amp;gt;&amp;amp;gt; 1&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;11&amp;lt;/tt&amp;gt; is represented in bits by &amp;lt;tt&amp;gt;1011&amp;lt;/tt&amp;gt; which when right shifted by 1 bit gives &amp;lt;tt&amp;gt;101&amp;lt;/tt&amp;gt; which is the decimal &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;amp;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise AND&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise AND of the numbers&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;5 &amp;amp;amp; 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bit-wise OR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise OR of the numbers&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;5 | 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;7&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
^&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bit-wise XOR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Bitwise XOR of the numbers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;5 ^ 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;6&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
~&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bit-wise invert&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
The bit-wise inversion of x is -(x+1)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;~5&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;-6&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;lt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Less Than&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns whether x is less than y. All comparison operators return &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;. Note the capitalization of these names.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;5 &amp;amp;lt; 3&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3 &amp;amp;lt; 5&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Comparisons can be chained arbitrarily: &amp;lt;tt&amp;gt;3 &amp;amp;lt; 5 &amp;amp;lt; 7&amp;lt;/tt&amp;gt; gives &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Greater Than&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Returns whether x is greater than y&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;5 &amp;amp;gt; 3&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. If both operands are numbers, they are first converted to a common type. Otherwise, it always returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;lt;=&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Less Than or Equal To&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns whether x is less than or equal to y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 3; y = 6; x &amp;amp;lt;= y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;gt;=&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Greater Than or Equal To&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns whether x is greater than or equal to y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 4; y = 3; x &amp;amp;gt;= 3&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;==&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Equal To&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compares if the objects are equal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 2; y = 2; x == y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 'str'; y = 'stR'; x == y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 'str'; y = 'str'; x == y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
!=&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Not Equal To&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compares if the objects are not equal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = 2; y = 3; x != y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
not&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean NOT&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If x is &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;, it returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;. If x is &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;, it returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = True; not x&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean AND&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x and y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; if x is &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt;, else it returns evaluation of y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = False; y = True; x and y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; since x is False. In this case, Python will not evaluate y since it knows that the left hand side of the 'and' expression is &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; which implies that the whole expression will be &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; irrespective of the other values. This is called short-circuit evaluation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean OR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If x is &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;, it returns True, else it returns evaluation of y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;x = True; y = False; x or y&amp;lt;/tt&amp;gt; returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. Short-circuit evaluation applies here as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shortcut for math operation and assignment ===&lt;br /&gt;
&lt;br /&gt;
It is common to run a math operation on a variable and then assign the result of the operation back to the variable, hence there is a shortcut for such expressions:&lt;br /&gt;
&lt;br /&gt;
You can write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
a = 2; a = a * 3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
a = 2; a *= 3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that &amp;lt;tt&amp;gt;var = var operation expression&amp;lt;/tt&amp;gt; becomes &amp;lt;tt&amp;gt;var operation= expression&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Evaluation Order ==&lt;br /&gt;
&lt;br /&gt;
If you had an expression such as &amp;lt;tt&amp;gt;2 + 3 * 4&amp;lt;/tt&amp;gt;, is the addition done first or the multiplication? Our high school maths tells us that the multiplication should be done first. This means that the multiplication operator has higher precedence than the addition operator.&lt;br /&gt;
&lt;br /&gt;
The following table gives the precedence table for Python, from the lowest precedence (least binding) to the highest precedence (most binding). This means that in a given expression, Python will first evaluate the operators and expressions lower in the table before the ones listed higher in the table.&lt;br /&gt;
&lt;br /&gt;
The following table, taken from the [http://docs.python.org/dev/3.0/reference/expressions.html#evaluation-order Python reference manual], is provided for the sake of completeness. It is far better to use parentheses to group operators and operands appropriately in order to explicitly specify the precedence. This makes the program more readable. See [[Python_en:Operators_and_Expressions#Changing the Order of Evaluation|Changing the Order of Evaluation]] below for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption&amp;gt;&lt;br /&gt;
Operator Precedence&lt;br /&gt;
&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Operator&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Description&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
lambda&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Lambda Expression&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean OR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean AND&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
not x&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Boolean NOT&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
in, not in&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Membership tests&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
is, is not&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Identity tests&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;lt;, &amp;amp;lt;=, &amp;amp;gt;, &amp;amp;gt;=, !=, ==&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Comparisons&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise OR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
^&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise XOR&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;amp;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise AND&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;amp;lt;&amp;amp;lt;, &amp;amp;gt;&amp;amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Shifts&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
+, -&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Addition and subtraction&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*, /, //, %&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Multiplication, Division, Floor Division and Remainder&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
+x, -x&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Positive, Negative&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
~x&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Bitwise NOT&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Exponentiation&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
x.attribute&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Attribute reference&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
x[index]&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Subscription&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
x[index1:index2]&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Slicing&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
f(arguments ...)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Function call&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
(expressions, ...)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Binding or tuple display&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
[expressions, ...]&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
List display&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
{key:datum, ...}&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
Dictionary display&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The operators which we have not already come across will be explained in later chapters.&lt;br /&gt;
&lt;br /&gt;
Operators with the ''same precedence'' are listed in the same row in the above table. For example, &amp;lt;tt&amp;gt;+&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;-&amp;lt;/tt&amp;gt; have the same precedence.&lt;br /&gt;
&lt;br /&gt;
== Changing the Order Of Evaluation ==&lt;br /&gt;
&lt;br /&gt;
To make the expressions more readable, we can use parentheses. For example, &amp;lt;tt&amp;gt;2 + (3 * 4)&amp;lt;/tt&amp;gt; is definitely easier to understand than &amp;lt;tt&amp;gt;2 + 3 * 4&amp;lt;/tt&amp;gt; which requires knowledge of the operator precedences. As with everything else, the parentheses should be used reasonably (do not overdo it) and should not be redundant (as in &amp;lt;tt&amp;gt;2 + (3 + 4)&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
There is an additional advantage to using parentheses - it helps us to change the order of evaluation. For example, if you want addition to be evaluated before multiplication in an expression, then you can write something like &amp;lt;tt&amp;gt;(2 + 3) * 4&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Associativity ==&lt;br /&gt;
&lt;br /&gt;
Operators are usually associated from left to right i.e. operators with same precedence are evaluated in a left to right manner. For example, &amp;lt;tt&amp;gt;2 + 3 + 4&amp;lt;/tt&amp;gt; is evaluated as &amp;lt;tt&amp;gt;(2 + 3) + 4&amp;lt;/tt&amp;gt;. Some operators like assignment operators have right to left associativity i.e. &amp;lt;tt&amp;gt;a = b = c&amp;lt;/tt&amp;gt; is treated as &amp;lt;tt&amp;gt;a = (b = c)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Expressions ==&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: expression.py&lt;br /&gt;
&lt;br /&gt;
length = 5&lt;br /&gt;
breadth = 2&lt;br /&gt;
&lt;br /&gt;
area = length * breadth&lt;br /&gt;
print('Area is', area)&lt;br /&gt;
print('Perimeter is', 2 * (length + breadth))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python expression.py&lt;br /&gt;
    Area is 10&lt;br /&gt;
    Perimeter is 14&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The length and breadth of the rectangle are stored in variables by the same name. We use these to calculate the area and perimeter of the rectangle with the help of expressions. We store the result of the expression &amp;lt;tt&amp;gt;length * breadth&amp;lt;/tt&amp;gt; in the variable &amp;lt;tt&amp;gt;area&amp;lt;/tt&amp;gt; and then print it using the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; function. In the second case, we directly use the value of the expression &amp;lt;tt&amp;gt;2 * (length + breadth)&amp;lt;/tt&amp;gt; in the print function.&lt;br /&gt;
&lt;br /&gt;
Also, notice how Python 'pretty-prints' the output. Even though we have not specified a space between &amp;lt;tt&amp;gt;'Area is'&amp;lt;/tt&amp;gt; and the variable &amp;lt;tt&amp;gt;area&amp;lt;/tt&amp;gt;, Python puts it for us so that we get a clean nice output and the program is much more readable this way (since we don't need to worry about spacing in the strings we use for output). This is an example of how Python makes life easy for the programmer.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have seen how to use operators, operands and expressions - these are the basic building blocks of any program. Next, we will see how to make use of these in our programs using statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Basics|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Control Flow|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Operators and Expressions]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Exceptions</id>
		<title>Python en:Exceptions</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Exceptions"/>
				<updated>2009-01-16T02:10:39Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* The with statement */ Adding explanation of the 'with' protocol&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Exceptions occur when certain ''exceptional'' situations occur in your program.  For example, what if you are going to read a file and the file does not exist? Or what if you accidentally deleted it when the program was running? Such situations are handled using '''exceptions'''.&lt;br /&gt;
&lt;br /&gt;
Similarly, what if your program had some invalid statements? This is handled by Python which '''raises''' its hands and tells you there is an '''error'''.&lt;br /&gt;
&lt;br /&gt;
== Errors ==&lt;br /&gt;
&lt;br /&gt;
Consider a simple &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; function call. What if we misspelt &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; as &amp;lt;tt&amp;gt;Print&amp;lt;/tt&amp;gt;? Note the capitalization. In this case, Python ''raises'' a syntax error.&lt;br /&gt;
&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; Print('Hello World')&lt;br /&gt;
    Traceback (most recent call last):&lt;br /&gt;
      File &amp;quot;&amp;lt;pyshell#0&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
        Print('Hello World')&lt;br /&gt;
    NameError: name 'Print' is not defined&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; print('Hello World')&lt;br /&gt;
    Hello World&lt;br /&gt;
&lt;br /&gt;
Observe that a &amp;lt;tt&amp;gt;NameError&amp;lt;/tt&amp;gt; is raised and also the location where the error was detected is printed. This is what an ''error handler'' for this error does.&lt;br /&gt;
&lt;br /&gt;
== Exceptions ==&lt;br /&gt;
&lt;br /&gt;
We will '''try''' to read input from the user. Press &amp;lt;tt&amp;gt;ctrl-d&amp;lt;/tt&amp;gt; and see what happens.&lt;br /&gt;
&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; s = input('Enter something --&amp;gt; ')&lt;br /&gt;
    Enter something --&amp;gt; &lt;br /&gt;
    Traceback (most recent call last):&lt;br /&gt;
      File &amp;quot;&amp;lt;pyshell#2&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
        s = input('Enter something --&amp;gt; ')&lt;br /&gt;
    EOFError: EOF when reading a line&lt;br /&gt;
&lt;br /&gt;
Python raises an error called &amp;lt;tt&amp;gt;EOFError&amp;lt;/tt&amp;gt; which basically means it found an ''end of file'' symbol (which is represented by &amp;lt;tt&amp;gt;ctrl-d&amp;lt;/tt&amp;gt;) when it did not expect to see it.&lt;br /&gt;
&lt;br /&gt;
== Handling Exceptions ==&lt;br /&gt;
&lt;br /&gt;
We can handle exceptions using the &amp;lt;tt&amp;gt;try..except&amp;lt;/tt&amp;gt; statement.  We basically put our usual statements within the try-block and put all our error handlers in the except-block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: try_except.py&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    text = input('Enter something --&amp;gt; ')&lt;br /&gt;
except EOFError:&lt;br /&gt;
    print('Why did you do an EOF on me?')&lt;br /&gt;
except KeyboardInterrupt:&lt;br /&gt;
    print('You cancelled the operation.')&lt;br /&gt;
else:&lt;br /&gt;
    print('You entered {0}'.format(text))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python try_except.py&lt;br /&gt;
    Enter something --&amp;gt;     # Press ctrl-d&lt;br /&gt;
    Why did you do an EOF on me?&lt;br /&gt;
    &lt;br /&gt;
    $ python try_except.py&lt;br /&gt;
    Enter something --&amp;gt;     # Press ctrl-c&lt;br /&gt;
    You cancelled the operation.&lt;br /&gt;
    &lt;br /&gt;
    $ python try_except.py&lt;br /&gt;
    Enter something --&amp;gt; no exceptions&lt;br /&gt;
    You entered no exceptions&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We put all the statements that might raise exceptions/errors inside the &amp;lt;tt&amp;gt;try&amp;lt;/tt&amp;gt; block and then put handlers for the appropriate errors/exceptions in the &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause/block. The &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause can handle a single specified error or exception, or a parenthesized list of errors/exceptions. If no names of errors or exceptions are supplied, it will handle ''all'' errors and exceptions.&lt;br /&gt;
&lt;br /&gt;
Note that there has to be at least one &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause associated with every &amp;lt;tt&amp;gt;try&amp;lt;/tt&amp;gt; clause. Otherwise, what's the point of having a try block?&lt;br /&gt;
&lt;br /&gt;
If any error or exception is not handled, then the default Python handler is called which just stops the execution of the program and prints an error message. We have already seen this in action above.&lt;br /&gt;
&lt;br /&gt;
You can also have an &amp;lt;tt&amp;gt;else&amp;lt;/tt&amp;gt; clause associated with a &amp;lt;tt&amp;gt;try..except&amp;lt;/tt&amp;gt; block. The &amp;lt;tt&amp;gt;else&amp;lt;/tt&amp;gt; clause is executed if no exception occurs.&lt;br /&gt;
&lt;br /&gt;
In the next example, we will also see how to get the exception object so that we can retrieve additional information.&lt;br /&gt;
&lt;br /&gt;
== Raising Exceptions ==&lt;br /&gt;
&lt;br /&gt;
You can ''raise'' exceptions using the &amp;lt;tt&amp;gt;raise&amp;lt;/tt&amp;gt; statement by providing the name of the error/exception and the exception object that is to be ''thrown''.&lt;br /&gt;
&lt;br /&gt;
The error or exception that you can arise should be class which directly or indirectly must be a derived class of the &amp;lt;tt&amp;gt;Exception&amp;lt;/tt&amp;gt; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: raising.py&lt;br /&gt;
&lt;br /&gt;
class ShortInputException(Exception):&lt;br /&gt;
    '''A user-defined exception class.'''&lt;br /&gt;
    def __init__(self, length, atleast):&lt;br /&gt;
        Exception.__init__(self)&lt;br /&gt;
        self.length = length&lt;br /&gt;
        self.atleast = atleast&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    text = input('Enter something --&amp;gt; ')&lt;br /&gt;
    if len(text) &amp;lt; 3:&lt;br /&gt;
        raise ShortInputException(len(text), 3)&lt;br /&gt;
    # Other work can continue as usual here&lt;br /&gt;
except EOFError:&lt;br /&gt;
    print('Why did you do an EOF on me?')&lt;br /&gt;
except ShortInputException as ex:&lt;br /&gt;
    print('ShortInputException: The input was {0} long, expected at least {1}'\&lt;br /&gt;
          .format(ex.length, ex.atleast))&lt;br /&gt;
else:&lt;br /&gt;
    print('No exception was raised.')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python raising.py&lt;br /&gt;
    Enter something --&amp;gt; a&lt;br /&gt;
    ShortInputException: The input was 1 long, expected at least 3&lt;br /&gt;
    &lt;br /&gt;
    $ python raising.py&lt;br /&gt;
    Enter something --&amp;gt; abc&lt;br /&gt;
    No exception was raised.&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Here, we are creating our own exception type. This new exception type is called &amp;lt;tt&amp;gt;ShortInputException&amp;lt;/tt&amp;gt;. It has two fields - &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; which is the length of the given input, and &amp;lt;tt&amp;gt;atleast&amp;lt;/tt&amp;gt; which is the minimum length that the program was expecting.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause, we mention the class of error which will be stored &amp;lt;tt&amp;gt;as&amp;lt;/tt&amp;gt; the variable name to hold the corresponding error/exception object. This is analogous to parameters and arguments in a function call. Within this particular &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause, we use the &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;atleast&amp;lt;/tt&amp;gt; fields of the exception object to print an appropriate message to the user.&lt;br /&gt;
&lt;br /&gt;
== Try .. Finally ==&lt;br /&gt;
&lt;br /&gt;
Suppose you are reading a file in your program. How do you ensure that the file object is closed properly whether or not an exception was raised? This can be done using the &amp;lt;tt&amp;gt;finally&amp;lt;/tt&amp;gt; block. Note that you can use an &amp;lt;tt&amp;gt;except&amp;lt;/tt&amp;gt; clause along with a &amp;lt;tt&amp;gt;finally&amp;lt;/tt&amp;gt; block for the same corresponding &amp;lt;tt&amp;gt;try&amp;lt;/tt&amp;gt; block. You will have to embed one within another if you want to use both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: finally.py&lt;br /&gt;
&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    f = open('poem.txt')&lt;br /&gt;
    while True: # our usual file-reading idiom&lt;br /&gt;
        line = f.readline()&lt;br /&gt;
        if len(line) == 0:&lt;br /&gt;
            break&lt;br /&gt;
        print(line, end='')&lt;br /&gt;
        time.sleep(2) # To make sure it runs for a while&lt;br /&gt;
except KeyboardInterrupt:&lt;br /&gt;
    print('!! You cancelled the reading from the file.')&lt;br /&gt;
finally:&lt;br /&gt;
    f.close()&lt;br /&gt;
    print('(Cleaning up: Closed the file)')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python finally.py&lt;br /&gt;
    Programming is fun&lt;br /&gt;
    When the work is done&lt;br /&gt;
    if you wanna make your work also fun:&lt;br /&gt;
    !! You cancelled the reading from the file.&lt;br /&gt;
    (Cleaning up: Closed the file)&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We do the usual file-reading stuff, but we have arbitrarily introduced sleeping for 2 seconds after printing each line using the &amp;lt;tt&amp;gt;time.sleep&amp;lt;/tt&amp;gt; function so that the program runs slowly (Python is very fast by nature). When the program is still running, press &amp;lt;tt&amp;gt;ctrl-c&amp;lt;/tt&amp;gt; to interrupt/cancel the program.&lt;br /&gt;
&lt;br /&gt;
Observe that the &amp;lt;tt&amp;gt;KeyboardInterrupt&amp;lt;/tt&amp;gt; exception is thrown and the program quits. However, before the program exits, the finally clause is executed and the file object is always closed.&lt;br /&gt;
&lt;br /&gt;
== The with statement ==&lt;br /&gt;
&lt;br /&gt;
Acquiring a resource in the &amp;lt;tt&amp;gt;try&amp;lt;/tt&amp;gt; block and subsequently releasing the resource in the &amp;lt;tt&amp;gt;finally&amp;lt;/tt&amp;gt; block is a common pattern. Hence, there is also a &amp;lt;tt&amp;gt;with&amp;lt;/tt&amp;gt; statement that enables this to be done in a clean manner:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: using_with.py&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;poem.txt&amp;quot;) as f:&lt;br /&gt;
    for line in f:&lt;br /&gt;
        print(line, end='')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The output should be same as the previous example. The difference here is that we are using the &amp;lt;tt&amp;gt;open&amp;lt;/tt&amp;gt; function with the &amp;lt;tt&amp;gt;with&amp;lt;/tt&amp;gt; statement - we leave the closing of the file to be done automatically by &amp;lt;tt&amp;gt;with open&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
What happens behind the scenes is that there is a protocol used by the &amp;lt;tt&amp;gt;with&amp;lt;/tt&amp;gt; statement. It fetches the object returned by the &amp;lt;tt&amp;gt;open&amp;lt;/tt&amp;gt; statement, let's call it &amp;quot;thefile&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
It ''always'' calls the &amp;lt;tt&amp;gt;thefile.__enter__&amp;lt;/tt&amp;gt; function before starting the block of code under it and ''always'' calls &amp;lt;tt&amp;gt;thefile.__exit__&amp;lt;/tt&amp;gt; after finishing the block of code.&lt;br /&gt;
&lt;br /&gt;
So the code that we would have written in a &amp;lt;tt&amp;gt;finally&amp;lt;/tt&amp;gt; block is should be taken care of automatically by the &amp;lt;tt&amp;gt;__exit__&amp;lt;/tt&amp;gt; method. This is what helps us to avoid having to use explicit &amp;lt;tt&amp;gt;try..finally&amp;lt;/tt&amp;gt; statements repeatedly.&lt;br /&gt;
&lt;br /&gt;
More discussion on this topic is beyond scope of this book, so please refer [http://www.python.org/dev/peps/pep-0343/ PEP 343] for comprehensive explanation.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have discussed the usage of the &amp;lt;tt&amp;gt;try..except&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;try..finally&amp;lt;/tt&amp;gt; statements. We have seen how to create our own exception types and how to raise exceptions as well.&lt;br /&gt;
&lt;br /&gt;
Next, we will explore the Python Standard Library.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Input Output|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Standard Library|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Exceptions]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:More</id>
		<title>Python en:More</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:More"/>
				<updated>2009-01-14T12:07:54Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* exec and eval */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
So far we have covered majority of the various aspects of Python that you will use. In this chapter, we will cover some more aspects that will make our knowledge of Python more well-rounded.&lt;br /&gt;
&lt;br /&gt;
== Passing tuples around ==&lt;br /&gt;
&lt;br /&gt;
Ever wished you could return two different values from a function? You can. All you have to do is use a tuple.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; def get_error_details():&lt;br /&gt;
...     return (2, 'second error details')&lt;br /&gt;
...&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; errnum, errstr = get_error_details()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; errnum&lt;br /&gt;
2&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; errstr&lt;br /&gt;
'second error details'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that the usage of &amp;lt;tt&amp;gt;a, b = &amp;amp;lt;some expression&amp;amp;gt;&amp;lt;/tt&amp;gt; interprets the result of the expression as a tuple with two values.&lt;br /&gt;
&lt;br /&gt;
If you want to interpret the results as &amp;lt;tt&amp;gt;(a, &amp;amp;lt;everything else&amp;amp;gt;)&amp;lt;/tt&amp;gt;, then you just need to star it just like you would in function parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a, *b = [1, 2, 3, 4]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a&lt;br /&gt;
1&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; b&lt;br /&gt;
[2, 3, 4]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This also means the fastest way to swap two variables in Python is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = 5; b = 8&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a, b = b, a&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a, b&lt;br /&gt;
(8, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Special Methods ==&lt;br /&gt;
&lt;br /&gt;
There are certain methods such as the &amp;lt;tt&amp;gt;__init__&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;__del__&amp;lt;/tt&amp;gt; methods which have special significance in classes.&lt;br /&gt;
&lt;br /&gt;
Special methods are used to mimic certain behaviors of built-in types. For example, if you want to use the &amp;lt;tt&amp;gt;x[key]&amp;lt;/tt&amp;gt; indexing operation for your class (just like you use it for lists and tuples), then all you have to do is implement the &amp;lt;tt&amp;gt;__getitem__()&amp;lt;/tt&amp;gt; method and your job is done. If you think about it, this is what Python does for the &amp;lt;tt&amp;gt;list&amp;lt;/tt&amp;gt; class itself!&lt;br /&gt;
&lt;br /&gt;
Some useful special methods are listed in the following table. If you want to know about all the special methods, [http://docs.python.org/dev/3.0/reference/datamodel.html#special-method-names see the manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption&amp;gt;&lt;br /&gt;
Some Special Methods&lt;br /&gt;
&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Name&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&lt;br /&gt;
Explanation&lt;br /&gt;
&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__init__(self, ...)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called just before the newly created object is returned for usage.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__del__(self)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Called just before the object is destroyed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__str__(self)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Called when we use the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; function or when &amp;lt;tt&amp;gt;str()&amp;lt;/tt&amp;gt; is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__lt__(self, other)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Called when the ''less than'' operator (&amp;amp;lt;) is used. Similarly, there are special methods for all the operators (+, &amp;amp;gt;, etc.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__getitem__(self, key)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Called when &amp;lt;tt&amp;gt;x[key]&amp;lt;/tt&amp;gt; indexing operation is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
__len__(self)&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Called when the built-in &amp;lt;tt&amp;gt;len()&amp;lt;/tt&amp;gt; function is used for the sequence object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Single Statement Blocks ==&lt;br /&gt;
&lt;br /&gt;
We have seen that each block of statements is set apart from the rest by its own indentation level. Well, there is one caveat. If your block of statements contains only one single statement, then you can specify it on the same line of, say, a conditional statement or looping statement. The following example should make this clear: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; flag = True&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; if flag: print 'Yes'&lt;br /&gt;
...&lt;br /&gt;
Yes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that the single statement is used in-place and not as a separate block.  Although, you can use this for making your program ''smaller'', I strongly recommend avoiding this short-cut method, except for error checking, mainly because it will be much easier to add an extra statement if you are using proper indentation.&lt;br /&gt;
&lt;br /&gt;
== Lambda Forms ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;lambda&amp;lt;/tt&amp;gt; statement is used to create new function objects and then return them at runtime.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: lambda.py&lt;br /&gt;
&lt;br /&gt;
def make_repeater(n):&lt;br /&gt;
    return lambda s: s * n&lt;br /&gt;
&lt;br /&gt;
twice = make_repeater(2)&lt;br /&gt;
&lt;br /&gt;
print(twice('word'))&lt;br /&gt;
print(twice(5))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python lambda.py&lt;br /&gt;
    wordword&lt;br /&gt;
    10&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Here, we use a function &amp;lt;tt&amp;gt;make_repeater&amp;lt;/tt&amp;gt; to create new function objects at runtime and return it. A &amp;lt;tt&amp;gt;lambda&amp;lt;/tt&amp;gt; statement is used to create the function object. Essentially, the &amp;lt;tt&amp;gt;lambda&amp;lt;/tt&amp;gt; takes a parameter followed by a single expression only which becomes the body of the function and the value of this expression is returned by the new function. Note that even a &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; statement cannot be used inside a lambda form, only expressions.&lt;br /&gt;
&lt;br /&gt;
; TODO&lt;br /&gt;
: Can we do a &amp;lt;tt&amp;gt;list.sort()&amp;lt;/tt&amp;gt; by providing a compare function created using &amp;lt;tt&amp;gt;lambda&amp;lt;/tt&amp;gt;?&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
points = [ { 'x' : 2, 'y' : 3 }, { 'x' : 4, 'y' : 1 } ]&lt;br /&gt;
# points.sort(lambda a, b : cmp(a['x'], b['x']))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== List Comprehension ==&lt;br /&gt;
&lt;br /&gt;
List comprehensions are used to derive a new list from an existing list. Suppose you have a list of numbers and you want to get a corresponding list with all the numbers multiplied by 2 only when the number itself is greater than 2. List comprehensions are ideal for such situations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: list_comprehension.py&lt;br /&gt;
&lt;br /&gt;
listone = [2, 3, 4]&lt;br /&gt;
listtwo = [2*i for i in listone if i &amp;gt; 2]&lt;br /&gt;
print(listtwo)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python list_comprehension.py&lt;br /&gt;
    [6, 8]&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
Here, we derive a new list by specifying the manipulation to be done (&amp;lt;tt&amp;gt;2*i&amp;lt;/tt&amp;gt;) when some condition is satisfied (&amp;lt;tt&amp;gt;if i &amp;amp;gt; 2&amp;lt;/tt&amp;gt;). Note that the original list remains unmodified. &lt;br /&gt;
&lt;br /&gt;
The advantage of using list comprehensions is that it reduces the amount of boilerplate code required when we use loops to process each element of a list and store it in a new list.&lt;br /&gt;
&lt;br /&gt;
== Receiving Tuples and Lists in Functions ==&lt;br /&gt;
&lt;br /&gt;
There is a special way of receiving parameters to a function as a tuple or a dictionary using the &amp;lt;tt&amp;gt;*&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;**&amp;lt;/tt&amp;gt; prefix respectively. This is useful when taking variable number of arguments in the function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; def powersum(power, *args):&lt;br /&gt;
...     '''Return the sum of each argument raised to specified power.'''&lt;br /&gt;
...     total = 0&lt;br /&gt;
...     for i in args:&lt;br /&gt;
...         total += pow(i, power)&lt;br /&gt;
...     return total&lt;br /&gt;
...&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; powersum(2, 3, 4)&lt;br /&gt;
25&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; powersum(2, 10)&lt;br /&gt;
100&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because we have a &amp;lt;tt&amp;gt;*&amp;lt;/tt&amp;gt; prefix on the &amp;lt;tt&amp;gt;args&amp;lt;/tt&amp;gt; variable, all extra arguments passed to the function are stored in &amp;lt;tt&amp;gt;args&amp;lt;/tt&amp;gt; as a tuple.  If a &amp;lt;tt&amp;gt;**&amp;lt;/tt&amp;gt; prefix had been used instead, the extra parameters would be considered to be key/value pairs of a dictionary.&lt;br /&gt;
&lt;br /&gt;
== exec and eval ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function is used to execute Python statements which are stored in a string or file, as opposed to written in the program itself. For example, we can generate a string containing Python code at runtime and then execute these statements using the &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; exec('print(&amp;quot;Hello World&amp;quot;)')&lt;br /&gt;
Hello World&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, the &amp;lt;tt&amp;gt;eval&amp;lt;/tt&amp;gt; function is used to evaluate valid Python expressions which are stored in a string. A simple example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; eval('2*3')&lt;br /&gt;
6&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The assert statement ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;assert&amp;lt;/tt&amp;gt; statement is used to assert that something is true. For example, if you are very sure that you will have at least one element in a list you are using and want to check this, and raise an error if it is not true, then &amp;lt;tt&amp;gt;assert&amp;lt;/tt&amp;gt; statement is ideal in this situation. When the assert statement fails, an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt; is raised.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; mylist = ['item']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; assert len(mylist) &amp;gt;= 1&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; mylist.pop()&lt;br /&gt;
'item'&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; mylist&lt;br /&gt;
[]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; assert len(mylist) &amp;gt;= 1&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
AssertionError&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;assert&amp;lt;/tt&amp;gt; statement should be used judiciously. Most of the time, it is better to catch exceptions, either handle the problem or display an error message to the user and then quit.&lt;br /&gt;
&lt;br /&gt;
== The repr function ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;repr&amp;lt;/tt&amp;gt; function is used to obtain a canonical string representation of the object. The interesting part is that you will have &amp;lt;tt&amp;gt;eval(repr(object)) == object&amp;lt;/tt&amp;gt; most of the time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; i = []&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; i.append('item')&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; repr(i)&lt;br /&gt;
&amp;quot;['item']&amp;quot;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; eval(repr(i))&lt;br /&gt;
['item']&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; eval(repr(i)) == i&lt;br /&gt;
True&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;repr&amp;lt;/tt&amp;gt; function is used to obtain a printable representation of the object. You can control what your classes return for the &amp;lt;tt&amp;gt;repr&amp;lt;/tt&amp;gt; function by defining the &amp;lt;tt&amp;gt;__repr__&amp;lt;/tt&amp;gt; method in your class.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have covered some more features of Python in this chapter and yet we haven't covered all the features of Python. However, at this stage, we have covered most of what you are ever going to use in practice. This is sufficient for you to get started with whatever programs you are going to create.&lt;br /&gt;
&lt;br /&gt;
Next, we will discuss how to explore Python further.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Standard Library|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:What Next|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|More]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python"/>
				<updated>2009-01-04T19:17:41Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;Thanks to Duncan Giles via email for alerting me about this&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Choose your Python version:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: thin solid gray;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
If you want to learn the current &amp;lt;strong&amp;gt;Python&amp;amp;nbsp;2.x&amp;lt;/strong&amp;gt;, [http://www.ibiblio.org/swaroopch/byteofpython/read/ read here] or [http://www.ibiblio.org/swaroopch/byteofpython/files/120/byteofpython_120.pdf download the PDF]&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
If you want to learn the new &amp;lt;strong&amp;gt;Python&amp;amp;nbsp;3.0&amp;lt;/strong&amp;gt;, [[Python_en:Table of Contents|read here]] or {{download|http://www.swaroopch.com/files/byteofpython/byte_of_python_v191.pdf|download the PDF}}&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
[http://www.swaroopch.com/buybook You can also buy a printed hardcopy.]&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
'A Byte of Python' is a book on programming using the Python language. It serves as a tutorial or guide to the Python language for a beginner audience. If all you know about computers is how to save text files, then this is the book for you.&lt;br /&gt;
&lt;br /&gt;
'''This book is updated for the new Python 3.0 language.''' If you are looking for a tutorial on the current Python 2.x version, please [http://www.ibiblio.org/swaroopch/byteofpython/files/120/ download the previous revision of the book]. On the same note, if you're wondering whether to learn Python 2.x or 3.x, then [http://www.b-list.org/weblog/2008/dec/05/python-3000/ read this article by James Bennett].&lt;br /&gt;
&lt;br /&gt;
== Who Reads 'A Byte of Python'? ==&lt;br /&gt;
&lt;br /&gt;
Here are what people are saying about the book:&lt;br /&gt;
&lt;br /&gt;
=== Feedback From Readers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This is the best beginner's tutorial I've ever seen! Thank you for your effort.&amp;lt;/p&amp;gt;  - &amp;lt;em&amp;gt;Walt Michalik&amp;lt;/em&amp;gt; (wmich50-at-theramp-dot-net)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;You've made the best Python tutorial I've found on the Net. Great work. Thanks! &amp;lt;/p&amp;gt; - &amp;lt;em&amp;gt;Joshua Robin&amp;lt;/em&amp;gt; (joshrob-at-poczta-dot-onet-dot-pl)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Hi, I'm from Dominican Republic. My name is Pavel, recently I read your book 'A Byte of Python' and I consider it excellent!!  :). I learnt much from all the examples. Your book is of great help for newbies like me... &amp;lt;/p&amp;gt; - &amp;lt;em&amp;gt;Pavel Simo&amp;lt;/em&amp;gt; (pavel-dot-simo-at-gmail-dot-com)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
I recently finished reading Byte of Python, and I thought I really ought to thank you. I was very sad to reach the final pages as I now have to go back to dull, tedious oreilly or etc.  manuals for learning about python. Anyway, I really appreciate your book &amp;lt;/p&amp;gt; - &amp;lt;em&amp;gt;Samuel Young&amp;lt;/em&amp;gt; (sy-one-three-seven-at-gmail-dot-com)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Dear Swaroop, I am taking a class from an instructor that has no interest in teaching. We are using Learning Python, second edition, by O'Reilly. It is not a text for beginner without any programming knowledge, and an instructor that should be working in another field.  Thank you very much for your book, without it I would be cluless about Python and programming. Thanks a million, you are able to 'break the message down' to a level that beginners can understand and not everyone can. &amp;lt;/p&amp;gt; - &amp;lt;em&amp;gt;Joseph Duarte&amp;lt;/em&amp;gt; (jduarte1-at-cfl-dot-rr-dot-com)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
I love your book! It is the greatest Python tutorial ever, and a very useful reference. Brilliant, a true masterpiece! Keep up the good work! &amp;lt;/p&amp;gt; - &amp;lt;em&amp;gt;Chris-Andr&amp;amp;#233; Sommerseth&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
I'm just e-mailing you to thank you for writing Byte of Python online.  I had been attempting Python for a few months prior to stumbling across your book, and although I made limited success with pyGame, I never completed a program.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Thanks to your simplification of the categories, Python actually seems a reachable goal. It seems like I have finally learned the foundations and I can continue into my real goal, game development.&amp;lt;/p&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Once again, thanks VERY much for placing such a structured and helpful guide to basic programming on the web.  It shoved me into and out of OOP with an understanding where two text books had failed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;em&amp;gt;- Matt Gallivan&amp;lt;/em&amp;gt; (m-underscore-gallivan12-at-hotmail-dot-com)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
I would like to thank you for your book 'A byte of python' which i myself find the best way to learn python. I am a 15 year old i live in egypt my name is Ahmed. Python was my second programming language i learn visual basic 6 at school but didn't enjoy it, however i really enjoyed learning python. I made the addressbook program and i was sucessful. i will try to start make more programs and read python programs (if you could tell me source that would be helpful). I will also start on learning java and if you can tell me where to find a tutorial as good as yours for java that would help me a lot. Thanx.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;em&amp;gt; - Ahmed Mohammed&amp;lt;/em&amp;gt; (sedo-underscore-91-at-hotmail-dot-com)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A wonderful resource for beginners wanting to learn more about Python is the 110-page PDF tutorial A Byte of Python by Swaroop C H. It is well-written, easy to follow, and may be the best introduction to Python programming available.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;em&amp;gt; - Drew Ames &amp;lt;/em&amp;gt; in an article on [http://www.linux.com/feature/126522 Scripting Scribus] published on Linux.com&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Yesterday I got through most of Byte of Python on my Nokia N800 and it's the easiest and most concise introduction to Python I have yet encountered. Highly recommended as a starting point for learning Python.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;em&amp;gt; - Jason Delport &amp;lt;/em&amp;gt; on his [http://paxmodept.com/telesto/blogitem.htm?id=627 weblog]&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Academic Courses ===&lt;br /&gt;
&lt;br /&gt;
This book is being used as instructional material in various educational institutions:&lt;br /&gt;
&lt;br /&gt;
# 'Principles of Programming Languages' course at [http://www.few.vu.nl/~nsilvis/PPL/2007/index.html Vrije Universiteit, Amsterdam]&lt;br /&gt;
# 'Basic Concepts of Computing' course at [http://www.cs.ucdavis.edu/courses/exp_course_desc/10.html University of California, Davis]&lt;br /&gt;
# 'Programming With Python' course at [http://www.people.fas.harvard.edu/~preshman/python_winter.html Harvard University]&lt;br /&gt;
# 'Introduction to Programming' course at [http://www.comp.leeds.ac.uk/acom1900/ University of Leeds]&lt;br /&gt;
# 'Introduction to Application Programming' course at [http://www.cs.bu.edu/courses/cs108/materials.html Boston University]&lt;br /&gt;
# 'Information Technology Skills for Meteorology' course at [http://gentry.metr.ou.edu/byteofpython/ University of Oklahoma]&lt;br /&gt;
# 'Geoprocessing' course at [http://www.msu.edu/~ashton/classes/825/index.html Michigan State University]&lt;br /&gt;
# 'Multi Agent Semantic Web Systems' course at the [http://homepages.inf.ed.ac.uk/ewan/masws/ University of Edinburgh]&lt;br /&gt;
&lt;br /&gt;
=== Even NASA ===&lt;br /&gt;
&lt;br /&gt;
The book is even used by NASA! It is being used in their [http://dsnra.jpl.nasa.gov/software/Python/byte-of-python/output/byteofpython_html/ Jet Propulsion Laboratory] with their Deep Space Network project.&lt;br /&gt;
&lt;br /&gt;
=== Official Recommendation ===&lt;br /&gt;
&lt;br /&gt;
This book has been listed on the official website for Python in the [http://www.python.org/doc/intros/ Full Tutorials] section, next to the official documentation.&lt;br /&gt;
&lt;br /&gt;
== License ==&lt;br /&gt;
&lt;br /&gt;
# This book is licensed under the [http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution-Share Alike 3.0 Unported] license.&lt;br /&gt;
#* This means:&lt;br /&gt;
#** You are free to Share i.e. to copy, distribute and transmit this book&lt;br /&gt;
#** You are free to Remix i.e. to adapt this book&lt;br /&gt;
#* Under the following conditions:&lt;br /&gt;
#** Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of this book).&lt;br /&gt;
#** Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.&lt;br /&gt;
#* For any reuse or distribution, you must make clear to others the license terms of this book.&lt;br /&gt;
#* Any of the above conditions can be waived if you get permission from the copyright holder.&lt;br /&gt;
#* Nothing in this license impairs or restricts the author's moral rights.&lt;br /&gt;
# Attribution ''must'' be shown by linking back to http://www.swaroopch.com/notes/Python and clearly indicating that the original text can be fetched from this location.&lt;br /&gt;
# All the code/scripts provided in this book is licensed under the [http://www.opensource.org/licenses/bsd-license.php 3-clause BSD License] unless otherwise noted.&lt;br /&gt;
# Volunteer contributions to this original book must be under this same license ''and'' the copyright must be assigned to the [[User:Swaroop|main author of this book]].&lt;br /&gt;
&lt;br /&gt;
== Read Now ==&lt;br /&gt;
&lt;br /&gt;
You can [[Python_en:Table of Contents|read the book online]] at [[Python_en:Table of Contents]].&lt;br /&gt;
&lt;br /&gt;
== Buy the Book ==&lt;br /&gt;
&lt;br /&gt;
[http://www.swaroopch.com/buybook A printed hardcopy of the book can be purchased] for your offline reading pleasure, and to support the continued development and improvement of this book.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.swaroopch.com/files/byteofpython/byte_of_python_v191.pdf PDF (631KB)]&lt;br /&gt;
* [http://www.swaroopch.com/files/byteofpython/byte_of_python_v191.xml Mediawiki XML dump (276KB)] (for advanced users only)&lt;br /&gt;
&lt;br /&gt;
'''If you wish to support the continued development of this book, please consider [https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=swaroop%40swaroopch%2ecom&amp;amp;item_name=A%20Byte%20of%20Python&amp;amp;no_shipping=0&amp;amp;no_note=1&amp;amp;tax=0&amp;amp;currency_code=USD&amp;amp;lc=IN&amp;amp;bn=PP%2dDonationsBF&amp;amp;charset=UTF%2d8 making a donation] or [http://www.swaroopch.com/buybook buy a printed hardcopy]'''.&lt;br /&gt;
&lt;br /&gt;
== Translations ==&lt;br /&gt;
&lt;br /&gt;
If you are interested in reading or contributing translations of this book to other human languages, please see [[Python_en:Translations|Translations]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Table of Contents|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Table_of_Contents</id>
		<title>Python en:Table of Contents</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Table_of_Contents"/>
				<updated>2008-12-22T07:37:06Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;Protected &amp;quot;Python en:Table of Contents&amp;quot; [edit=sysop:move=sysop]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
*[[Python|Front Page]]&lt;br /&gt;
&lt;br /&gt;
#[[Python en:Translations|Translations]] &lt;br /&gt;
#[[Python en:Preface|Preface]] &lt;br /&gt;
#[[Python en:Introduction|Introduction]] &lt;br /&gt;
#[[Python en:Installation|Installation]] &lt;br /&gt;
#[[Python en:First Steps|First Steps]] &lt;br /&gt;
#[[Python en:Basics|Basics]] &lt;br /&gt;
#[[Python en:Operators and Expressions|Operators and Expressions]] &lt;br /&gt;
#[[Python en:Control Flow|Control Flow]] &lt;br /&gt;
#[[Python en:Functions|Functions]] &lt;br /&gt;
#[[Python en:Modules|Modules]] &lt;br /&gt;
#[[Python en:Data Structures|Data Structures]] &lt;br /&gt;
#[[Python en:Problem Solving|Problem Solving]] &lt;br /&gt;
#[[Python en:Object Oriented Programming|Object Oriented Programming]] &lt;br /&gt;
#[[Python en:Input Output|Input Output]] &lt;br /&gt;
#[[Python en:Exceptions|Exceptions]] &lt;br /&gt;
#[[Python en:Standard Library|Standard Library]] &lt;br /&gt;
#[[Python en:More|More]] &lt;br /&gt;
#[[Python en:What Next|What Next]] &lt;br /&gt;
#[[Python en:Appendix FLOSS|Appendix: FLOSS]] &lt;br /&gt;
#[[Python en:Appendix About|Appendix: About]] &lt;br /&gt;
#[[Python en:Appendix Revision History|Appendix: Revision History]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python|Previous]]&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python en:Translations|Next]]&amp;lt;/span&amp;gt; &lt;br /&gt;
&amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; &lt;br /&gt;
[[Category:A_Byte_of_Python|Table of Contents]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Translation_Howto</id>
		<title>Python en:Translation Howto</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Translation_Howto"/>
				<updated>2008-09-07T05:32:05Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;Protected &amp;quot;Python en:Translation Howto&amp;quot; [edit=sysop:move=sysop]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a [http://www.swaroopch.com/mediawiki/index.php?title=Special:UserLogin&amp;amp;returnto=Python login ID]&lt;br /&gt;
* Add 2-3 lines about yourself and which translation you are working on in your user page which is at &amp;lt;tt&amp;gt;User:&amp;amp;lt;your login id&amp;amp;gt;&amp;lt;/tt&amp;gt; (for example, [[User:Swaroop]])&lt;br /&gt;
* Add information about the language, your motivation and the link to the [[Python_en:Translations]] page following the format used by others at the top of the page.&lt;br /&gt;
* Choose your two-letter shortcode for your language, such as &amp;quot;en&amp;quot; for English and &amp;quot;cn&amp;quot; for Chinese, or something like &amp;quot;nb-no&amp;quot; for Norwegian bokmål translation.&lt;br /&gt;
** This means your translation's pages should be prefixed with &amp;quot;Python:&amp;amp;lt;two-letter shortcode&amp;amp;gt;&amp;quot; such as [[Python_en:Preface]] or [[Python_nb-no:Forord]]&lt;br /&gt;
* Choose your category in English such as &amp;quot;A Byte of Python in Norwegian&amp;quot; or &amp;quot;A Byte of Python in Chinese&amp;quot;.&lt;br /&gt;
** This is important because all your pages can be easily located if they are in the same category.&lt;br /&gt;
* The basic template of all of your pages should be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your translation here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python in &amp;amp;lt;your language&amp;amp;gt;|&amp;amp;lt;Page Name&amp;amp;gt;]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Start translating with the text from [[Python_en:Table of Contents]]&lt;br /&gt;
** See [[Help:Editing]] on how to write in wiki format.&lt;br /&gt;
* You can create a [[Help:Collections|Collection]] (such as the [[MediaWiki:Collections/A Byte of Python|English version collection]]) to create PDFs of your translation.&lt;br /&gt;
* Do [[User:Swaroop|write to me]] and let me know when you start the translation, as well as if you have any doubts or suggestions.&lt;br /&gt;
* All the best!&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Translation_Howto]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Appendix_Changes_for_Python_3000</id>
		<title>Python en:Appendix Changes for Python 3000</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Appendix_Changes_for_Python_3000"/>
				<updated>2008-09-03T21:32:30Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Vim and Emacs editors&lt;br /&gt;
** http://henry.precheur.org/2008/4/18/Indenting%20Python%20with%20VIM.html&lt;br /&gt;
** http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/&lt;br /&gt;
* String - unicode only&lt;br /&gt;
** http://docs.python.org/dev/3.0/tutorial/introduction.html#about-unicode&lt;br /&gt;
* Non-ASCII identifiers allowed&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3131/&lt;br /&gt;
* ''print()'' function&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3105/&lt;br /&gt;
* ''raw_input()'' becomes ''input()''&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3111/&lt;br /&gt;
* Integer Literal Support and Syntax&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3127/&lt;br /&gt;
* ''nonlocal'' statement&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3104/&lt;br /&gt;
* Functions can take * argument (varargs) for lists and keyword-only arguments&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3102/&lt;br /&gt;
* Functions can have annotations (make a passing note?)&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3107/&lt;br /&gt;
* Better explanation of modules, packages and their organization (including ''__init__.py'', etc.)&lt;br /&gt;
** http://ivory.idyll.org/articles/advanced-swc/#packages&lt;br /&gt;
* String ''.format()'' instead of ''%'' operator&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3101/&lt;br /&gt;
** http://docs.python.org/dev/library/string.html#formatstrings&lt;br /&gt;
* Dict method changes&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3106/&lt;br /&gt;
* Built-in set class, in data structures chapter&lt;br /&gt;
* Problem Solving&lt;br /&gt;
** Use http://gnuwin32.sourceforge.net/packages/zip.htm on Windows&lt;br /&gt;
* Classes&lt;br /&gt;
** http://docs.python.org/dev/3.0/reference/datamodel.html&lt;br /&gt;
* Metaclasses&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3115/&lt;br /&gt;
* Abstract Base Classes&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3119/&lt;br /&gt;
* Not sure if any changes required for New I/O&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3116/&lt;br /&gt;
* Exception handling&lt;br /&gt;
** http://www.python.org/dev/peps/pep-0352/&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3109/&lt;br /&gt;
** http://www.python.org/dev/peps/pep-3110/&lt;br /&gt;
* Standard Library - interesting additions&lt;br /&gt;
** Reorganization : http://www.python.org/dev/peps/pep-3108/&lt;br /&gt;
** http://docs.python.org/dev/library/warnings.html&lt;br /&gt;
** http://docs.python.org/dev/library/logging.html (important)&lt;br /&gt;
** http://docs.python.org/dev/library/urllib.html&lt;br /&gt;
** http://docs.python.org/dev/library/json.html&lt;br /&gt;
** Debugging&lt;br /&gt;
*** http://docs.python.org/dev/library/pdb.html&lt;br /&gt;
*** http://docs.python.org/dev/3.0/library/trace.html&lt;br /&gt;
*** eval, repr/ascii functions&lt;br /&gt;
** getopt/optparse - how to write a standard command-line program using python?&lt;br /&gt;
*** something like replace?&lt;br /&gt;
**** http://hpux.connect.org.uk/hppd/hpux/Users/replace-2.24/man.html&lt;br /&gt;
* More&lt;br /&gt;
** Unpacking can take * argument&lt;br /&gt;
*** http://www.python.org/dev/peps/pep-3132/&lt;br /&gt;
** ''with'' statement&lt;br /&gt;
*** http://www.python.org/dev/peps/pep-0343/&lt;br /&gt;
* What Next?&lt;br /&gt;
** Implement 'replace'&lt;br /&gt;
*** http://unixhelp.ed.ac.uk/CGI/man-cgi?replace&lt;br /&gt;
** Mention use of PyPI&lt;br /&gt;
** Q&amp;amp;A&lt;br /&gt;
*** http://docs.python.org/dev/howto/doanddont.html&lt;br /&gt;
*** http://www.python.org/doc/faq/general/&lt;br /&gt;
*** http://norvig.com/python-iaq.html&lt;br /&gt;
** Books &amp;amp; Resources&lt;br /&gt;
*** http://www.coderholic.com/free-python-programming-books/&lt;br /&gt;
*** http://pythonpapers.org&lt;br /&gt;
*** http://www.mobilepythonbook.org&lt;br /&gt;
*** http://effbot.org/zone/&lt;br /&gt;
*** Links at the end of every Python-URL! email&lt;br /&gt;
**** http://groups.google.com/group/comp.lang.python.announce/t/37de95ef0326293d&lt;br /&gt;
** Examples&lt;br /&gt;
*** http://www.rosettacode.org&lt;br /&gt;
*** http://dev.fyicenter.com/Interview-Questions/Python/index.html&lt;br /&gt;
*** http://www.java2s.com/Code/Python/CatalogPython.htm&lt;br /&gt;
** Tips &amp;amp; Tricks&lt;br /&gt;
*** http://www.siafoo.net/article/52&lt;br /&gt;
&lt;br /&gt;
[[Category:A_Byte_of_Python|Appendix Changes for Python 3000]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Appendix_Revision_History</id>
		<title>Python en:Appendix Revision History</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Appendix_Revision_History"/>
				<updated>2008-09-03T21:25:20Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
*1.90 &lt;br /&gt;
**04/09/2008 and still in progress &lt;br /&gt;
**Revival after a gap of 3.5 years! &lt;br /&gt;
**[[Python_en:Appendix Changes for Python 3000|Updating to Python 3.0]]&lt;br /&gt;
**Rewrite using MediaWiki (again) &lt;br /&gt;
*1.20 &lt;br /&gt;
**13/01/2005 &lt;br /&gt;
**Complete rewrite using Quanta+ on FC3 with lot of corrections and updates. Many new examples. Rewrote my DocBook setup from scratch. &lt;br /&gt;
*1.15 &lt;br /&gt;
**28/03/2004 &lt;br /&gt;
**Minor revisions &lt;br /&gt;
*1.12 &lt;br /&gt;
**16/03/2004 &lt;br /&gt;
**Additions and corrections. &lt;br /&gt;
*1.10 &lt;br /&gt;
**09/03/2004 &lt;br /&gt;
**More typo corrections, thanks to many enthusiastic and helpful readers. &lt;br /&gt;
*1.00 &lt;br /&gt;
**08/03/2004 &lt;br /&gt;
**After tremendous feedback and suggestions from readers, I have made significant revisions to the content along with typo corrections. &lt;br /&gt;
*0.99 &lt;br /&gt;
**22/02/2004 &lt;br /&gt;
**Added a new chapter on modules. Added details about variable number of arguments in functions. &lt;br /&gt;
*0.98 &lt;br /&gt;
**16/02/2004 &lt;br /&gt;
**Wrote a Python script and CSS stylesheet to improve XHTML output, including a crude-yet-functional lexical analyzer for automatic VIM-like syntax highlighting of the program listings. &lt;br /&gt;
*0.97 &lt;br /&gt;
**13/02/2004 &lt;br /&gt;
**Another completely rewritten draft, in DocBook XML (again). Book has improved a lot - it is more coherent and readable. &lt;br /&gt;
*0.93 &lt;br /&gt;
**25/01/2004 &lt;br /&gt;
**Added IDLE talk and more Windows-specific stuff &lt;br /&gt;
*0.92 &lt;br /&gt;
**05/01/2004 &lt;br /&gt;
**Changes to few examples. &lt;br /&gt;
*0.91 &lt;br /&gt;
**30/12/2003 &lt;br /&gt;
**Corrected typos. Improvised many topics. &lt;br /&gt;
*0.90 &lt;br /&gt;
**18/12/2003 &lt;br /&gt;
**Added 2 more chapters. OpenOffice format with revisions. &lt;br /&gt;
*0.60 &lt;br /&gt;
**21/11/2003 &lt;br /&gt;
**Fully rewritten and expanded. &lt;br /&gt;
*0.20 &lt;br /&gt;
**20/11/2003 &lt;br /&gt;
**Corrected some typos and errors. &lt;br /&gt;
*0.15 &lt;br /&gt;
**20/11/2003 &lt;br /&gt;
**Converted to DocBook XML. &lt;br /&gt;
*0.10 &lt;br /&gt;
**14/11/2003 &lt;br /&gt;
**Initial draft using KWord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python en:Appendix About|Previous]]&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python en:Table of Contents|Back to Table of Contents]]&amp;lt;/span&amp;gt; &lt;br /&gt;
&amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; &lt;br /&gt;
[[Category:A_Byte_of_Python|Appendix Revision History]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	<entry>
		<id>http://wiki.darenet.org/Python_en:Appendix_About</id>
		<title>Python en:Appendix About</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/Python_en:Appendix_About"/>
				<updated>2008-09-03T21:13:21Z</updated>
		
		<summary type="html">&lt;p&gt;Swaroop:&amp;#32;/* Now */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Colophon ==&lt;br /&gt;
&lt;br /&gt;
Almost all of the software that I have used in the creation of this book are ''[[Python_en:Appendix FLOSS|free and open source software]]''.&lt;br /&gt;
&lt;br /&gt;
=== Birth of the Book ===&lt;br /&gt;
&lt;br /&gt;
In the first draft of this book, I had used Red Hat 9.0 Linux as the foundation of my setup and in the sixth draft, I used Fedora Core 3 Linux as the basis of my setup.&lt;br /&gt;
&lt;br /&gt;
Initially, I was using KWord to write the book (as explained in the [[Python_en:Preface#History Lesson|History Lesson]] in the preface).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Teenage Years ===&lt;br /&gt;
&lt;br /&gt;
Later, I switched to DocBook XML using Kate but I found it too tedious. So, I switched to OpenOffice which was just excellent with the level of control it provided for formatting as well as the PDF generation, but it produced very sloppy HTML from the document.&lt;br /&gt;
&lt;br /&gt;
Finally, I discovered XEmacs and I rewrote the book from scratch in DocBook XML (again) after I decided that this format was the long term solution.&lt;br /&gt;
&lt;br /&gt;
In the sixth draft, I decided to use Quanta+ to do all the editing. The standard XSL stylesheets that came with Fedora Core 3 Linux were being used. The standard default fonts are used as well. The standard fonts are used as well.  However, I had written a CSS document to give color and style to the HTML pages. I had also written a crude lexical analyzer, in Python of course, which automatically provides syntax highlighting to all the program listings.&lt;br /&gt;
&lt;br /&gt;
=== Now ===&lt;br /&gt;
&lt;br /&gt;
For this seventh draft, I'm using [http://www.mediawiki.org MediaWiki] as the basis of my [http://www.swaroopch.com/notes/ setup]. Now I edit everything online and the readers can directly read/edit/discuss within the wiki website.&lt;br /&gt;
&lt;br /&gt;
I still use Vim for editing thanks to the [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith extension for Firefox] that integrates with Vim.&lt;br /&gt;
&lt;br /&gt;
== About The Author ==&lt;br /&gt;
&lt;br /&gt;
http://www.swaroopch.com/about/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Appendix FLOSS|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:Appendix Revision History|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Appendix About]]&lt;/div&gt;</summary>
		<author><name>Swaroop</name></author>	</entry>

	</feed>