<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>http://s-and-j.co.uk/wiki/index.php?action=history&amp;feed=atom&amp;title=Python</id>
	<title>Python - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://s-and-j.co.uk/wiki/index.php?action=history&amp;feed=atom&amp;title=Python"/>
	<link rel="alternate" type="text/html" href="http://s-and-j.co.uk/wiki/index.php?title=Python&amp;action=history"/>
	<updated>2026-11-24T18:21:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://s-and-j.co.uk/wiki/index.php?title=Python&amp;diff=281&amp;oldid=prev</id>
		<title>Simon: Added category &#039;Programming Languages&#039;</title>
		<link rel="alternate" type="text/html" href="http://s-and-j.co.uk/wiki/index.php?title=Python&amp;diff=281&amp;oldid=prev"/>
		<updated>2022-07-31T13:43:23Z</updated>

		<summary type="html">&lt;p&gt;Added category &amp;#039;Programming Languages&amp;#039;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:43, 31 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l205&quot;&gt;Line 205:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 205:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Oops.  I broke Python.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Oops.  I broke Python.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category: Programming Languages]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Python]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Python]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Simon</name></author>
	</entry>
	<entry>
		<id>http://s-and-j.co.uk/wiki/index.php?title=Python&amp;diff=65&amp;oldid=prev</id>
		<title>Simon: Recreated page</title>
		<link rel="alternate" type="text/html" href="http://s-and-j.co.uk/wiki/index.php?title=Python&amp;diff=65&amp;oldid=prev"/>
		<updated>2017-06-15T19:46:23Z</updated>

		<summary type="html">&lt;p&gt;Recreated page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Python, the programming language =&lt;br /&gt;
&lt;br /&gt;
== Quick Reference ==&lt;br /&gt;
* &amp;lt;code&amp;gt;for x in range(12) :  &amp;lt;br&amp;gt;  else :&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;while condition :  &amp;lt;br&amp;gt;  else :&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;def nameOfIt(parameter, parameter) :&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;7 / 3&amp;lt;/code&amp;gt; = 2 &amp;amp;nbsp; and &amp;amp;nbsp; &amp;lt;code&amp;gt;7 / 3.0&amp;lt;/code&amp;gt; = 2.33333333333 &amp;amp;nbsp; but &amp;amp;nbsp; &amp;lt;code&amp;gt;float(7 / 3)&amp;lt;/code&amp;gt; = 2.0&lt;br /&gt;
* &amp;lt;code&amp;gt;if x == y :&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;quot;&amp;quot;&amp;quot; Multi-line&amp;lt;br&amp;gt;comments &amp;quot;&amp;quot;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list = [&amp;quot;cat&amp;quot;, 2, 3.132, &amp;#039;stuff and nonsense&amp;#039;]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;print len(list)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list.append(&amp;quot;New item&amp;quot;)&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;list.insert(4,&amp;quot;Another item&amp;quot;)&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;list.append([&amp;quot;Item&amp;quot;,&amp;#039;thing&amp;#039;,13])&amp;lt;/code&amp;gt; to add more than one item &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;list.pop(n)&amp;lt;/code&amp;gt; removes the nth item from the list &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;list.remove(&amp;quot;Value&amp;quot;)&amp;lt;/code&amp;gt; removes first instance of &amp;quot;Value&amp;quot; from the list &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;find = list.index(&amp;quot;Item&amp;quot;)&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;list.sort()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;Reversedlist = list[::-1]&amp;lt;/code&amp;gt;  using a negative stride to reverse a list&lt;br /&gt;
* &amp;lt;code&amp;gt;dictionary = { &amp;#039;Key&amp;#039;: &amp;#039;value&amp;#039;, &amp;#039;Age&amp;#039;: 42, &amp;#039;Name&amp;#039;, &amp;quot;Fred&amp;quot; }   # the keys are unique&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;print dictionary[&amp;#039;Key&amp;#039;]&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;dictionary[&amp;#039;Key&amp;#039;] = 21&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;dictionary[&amp;quot;New thing&amp;quot;] = &amp;quot;Value&amp;quot;&amp;lt;/code&amp;gt; (no .insert is required)  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;del dictionary[&amp;#039;Key&amp;#039;]&amp;lt;/code&amp;gt; (removes a key and its value)  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;dictionary.remove(&amp;quot;Fred&amp;quot;)&amp;lt;/code&amp;gt; removes a key with the value of &amp;quot;Fred&amp;quot;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;print dictionary.keys()&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;print dictionary.values()&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;dictionary.has_key(&amp;quot;Bill&amp;quot;)&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;Age in dictionary    # True or False according to whether the key is in the dictionary&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;newList = [x for x in &amp;#039;&amp;#039;list&amp;#039;&amp;#039; if &amp;#039;&amp;#039;condition&amp;#039;&amp;#039;]&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt;  &amp;lt;code&amp;gt;even_squares_to_50 = [x**2 for x in range(1,51) if x % 2 == 0]&amp;lt;/code&amp;gt;&lt;br /&gt;
* Anonymous functions: &amp;lt;code&amp;gt;lambda &amp;#039;&amp;#039;variable&amp;#039;&amp;#039;: expression&amp;lt;/code&amp;gt;&lt;br /&gt;
 # normal function&lt;br /&gt;
 my_list = range(16)&lt;br /&gt;
 def by_three(x) :&lt;br /&gt;
     return x % 3 == 0&lt;br /&gt;
 print filter(by_three,my_list)&lt;br /&gt;
 &amp;gt; [0, 3, 6, 9, 12, 15]&lt;br /&gt;
&lt;br /&gt;
 # anonymous function&lt;br /&gt;
 my_list = range(16)&lt;br /&gt;
 print filter(lambda x: x % 3 == 0, my_list)&lt;br /&gt;
 &amp;gt; [0, 3, 6, 9, 12, 15]&lt;br /&gt;
&lt;br /&gt;
== Getting help and providing help() using a docstring ==&lt;br /&gt;
To get to the description of a built-in function:&lt;br /&gt;
 help(&amp;#039;&amp;#039;function&amp;#039;&amp;#039;)&lt;br /&gt;
To provide help() in a home-made function - called a &amp;#039;docstring&amp;#039;:&lt;br /&gt;
 def area(base, height) :&lt;br /&gt;
     &amp;lt;nowiki&amp;gt;&amp;#039;&amp;#039;&amp;#039;&amp;lt;/nowiki&amp;gt;(number,number) -&amp;gt; number&lt;br /&gt;
 &lt;br /&gt;
     Returns the area of a triangle with dimensions base and height.&lt;br /&gt;
     &amp;lt;nowiki&amp;gt;&amp;#039;&amp;#039;&amp;#039;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     return base *height / 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Finding functions with dir() ==&lt;br /&gt;
 dir(_builtins__)&lt;br /&gt;
 help(abs)&lt;br /&gt;
A &amp;#039;&amp;#039;method&amp;#039;&amp;#039; is a function inside an object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Classes example ==&lt;br /&gt;
 # Class definition&lt;br /&gt;
 class Animal(object):&lt;br /&gt;
 	&amp;quot;&amp;quot;&amp;quot;Makes cute animals.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
 	is_alive = True&lt;br /&gt;
 	health = &amp;quot;good&amp;quot;&lt;br /&gt;
 	# For initializing our instance objects&lt;br /&gt;
 	def __init__(self, name, age, is_hungry):&lt;br /&gt;
 		self.name = name&lt;br /&gt;
 		self.age = age&lt;br /&gt;
 		self.is_hungry = is_hungry&lt;br /&gt;
 	# Add your method here!&lt;br /&gt;
 	def description(self):&lt;br /&gt;
 		print self.name, self.age&lt;br /&gt;
 # Note that self is only used in the __init__()&lt;br /&gt;
 # function definition; we don&amp;#039;t need to pass it&lt;br /&gt;
 # to our instance objects.&lt;br /&gt;
 &lt;br /&gt;
 zebra   = Animal(&amp;quot;Jeffrey&amp;quot;, 2, True)&lt;br /&gt;
 giraffe = Animal(&amp;quot;Bruce&amp;quot;  , 1, False)&lt;br /&gt;
 panda   = Animal(&amp;quot;Chad&amp;quot;   , 7, True)&lt;br /&gt;
 hippo   = Animal(&amp;quot;Harry&amp;quot;  , 8, True)&lt;br /&gt;
 &lt;br /&gt;
 print zebra.name  , zebra.age  , zebra.is_hungry&lt;br /&gt;
 print giraffe.name, giraffe.age, giraffe.is_hungry&lt;br /&gt;
 print panda.name  , panda.age  , panda.is_hungry&lt;br /&gt;
 &lt;br /&gt;
 hippo.description()&lt;br /&gt;
 print hippo.health, sloth.health, ocelot.health&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File handling ==&lt;br /&gt;
There are four methods for reading a file:&lt;br /&gt;
   filename = &amp;quot;../whatever/file.dat&amp;quot;&lt;br /&gt;
   file_ref = open(filename,&amp;#039;r&amp;#039;)       # &amp;#039;w&amp;#039; to write and &amp;#039;a&amp;#039; to append&lt;br /&gt;
 &amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; record = file_ref.readline()        # will have &amp;#039;\n&amp;#039; at the end, or null at the end of the file&lt;br /&gt;
   print(record, end=&amp;lt;nowiki&amp;gt;&amp;#039;&amp;#039;&amp;lt;/nowiki&amp;gt;)               # prevents print() from appending a newline.&lt;br /&gt;
   file_ref.close()&lt;br /&gt;
   &lt;br /&gt;
 &amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; for record in file_ref :&lt;br /&gt;
       print(record, end=&amp;lt;nowiki&amp;gt;&amp;#039;&amp;#039;&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
   &lt;br /&gt;
 &amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; entire_contents = file_ref.read()   # read() returns the entire file&lt;br /&gt;
   &lt;br /&gt;
 &amp;lt;sub&amp;gt;4&amp;lt;/sub&amp;gt; record_list = file_ref.readlines()  # readlines() returns all the records in the file as a list.&lt;br /&gt;
&lt;br /&gt;
Writing:&lt;br /&gt;
 import tkinter.filedialog&lt;br /&gt;
 filename = tkinter.filedialog.askopenfilename()    # a graphical file prompt for a file to open&lt;br /&gt;
 filename = tkinter.filedialog.asksaveasfilename()  # a graphical file prompt for a file name to write to&lt;br /&gt;
 file_ref = open(filename,&amp;#039;w&amp;#039;)       # &amp;#039;w&amp;#039; to write and &amp;#039;a&amp;#039; to append&lt;br /&gt;
 record = &amp;quot;Blah\n&amp;quot;&lt;br /&gt;
 file_ref.write(record)              # write() does not append a newline&lt;br /&gt;
 file_ref.close()&lt;br /&gt;
&lt;br /&gt;
== Grizzles ==&lt;br /&gt;
* The use of colons with &amp;#039;for&amp;#039; and &amp;#039;if&amp;#039;.  The are immediately followed by indentation.  Python says it uses white space to determine structure, not { } or other constructs.  The reality is that &amp;lt;nowiki&amp;gt;&amp;#039;&amp;lt;/nowiki&amp;gt;&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;&amp;lt;nowiki&amp;gt;&amp;#039;&amp;lt;/nowiki&amp;gt; is determining the structure and the whitespace merely an inconvenience to the programmer.  Personally, I like the whitespace idea, but the &amp;lt;nowiki&amp;gt;&amp;#039;&amp;lt;/nowiki&amp;gt;&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;&amp;lt;nowiki&amp;gt;&amp;#039;&amp;lt;/nowiki&amp;gt; is an unnecessary faff.  And do you know why it is there?  Supposedly to allow text editors to highlight code properly - but if indenting with whitespace determines structure, then why can&amp;#039;t the editors do the same?&lt;br /&gt;
&lt;br /&gt;
* Immutable strings.  There is no reason for this constraint.  It was done to make memory management easier and very slightly more performance efficient, but it is a constraint that has had knock-on effects through other parts of the language definition.  As a constraint to improve performance ... who the hell cares about memory manipulation in RAM time any more?  That&amp;#039;s so 1970s.  There is no real reason why one cannot say &amp;lt;code&amp;gt;myString[7:10] = &amp;quot;replacement text&amp;quot;&amp;lt;/code&amp;gt;.  It was even possible in QuickBASIC!&lt;br /&gt;
&lt;br /&gt;
* So are strings lists or not?  One can treat strings as arrays using &amp;lt;code&amp;gt;for x in &amp;quot;How long&amp;quot; : print x&amp;lt;/code&amp;gt;, so why not &amp;lt;code&amp;gt;MyString[3] = &amp;quot;z&amp;quot;&amp;lt;/code&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
* Version 2 or version 3?  Just fork the God-damned schizophrenic language into two and get it over and done with!  At least then version 3 can die in peace.&lt;br /&gt;
&lt;br /&gt;
* Functions or methods?  Methods or functions?  Which is it to be, Python?  Why can&amp;#039;t I say &amp;lt;code&amp;gt;sort(myTable)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;myString.length()&amp;lt;/code&amp;gt;  This is just sloppiness that makes it hard for newbies.  I thought Python was meant to be easy for newbies, and with only one way to do things?  Hmm?&lt;br /&gt;
&lt;br /&gt;
* Count from 0 in indexes, except for terminators.  Eh?  Why is a substring &amp;lt;code&amp;gt;myString[2:4]&amp;lt;/code&amp;gt; only 2 characters long?  I have no trouble with counting from zero, but why is the &amp;lt;code&amp;gt;[:&amp;#039;&amp;#039;y&amp;#039;&amp;#039;]&amp;lt;/code&amp;gt; parameter one higher than it needs to be?  It just causes confusion.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;__init__()&amp;lt;/code&amp;gt; to initialise classes/objects.  What sort of name it that?  What was wrong with &amp;lt;code&amp;gt;init()&amp;lt;/code&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Confusion ==&lt;br /&gt;
* Passing variables to functions - why bother?  Since passing a variable to a function, then changing the variable, changes the global variable, this means variables in functions are not local to the function.  In which case, why bother passing parameters to the function at all and not just work on the global variable, like one would in BASIC?  Unless the function is going into an external library, there is rarely ever going to be any point passing in parameters.  In fact, &amp;#039;&amp;#039;&amp;#039;why aren&amp;#039;t variables passed as parameters to functions treated as local variables?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Why &amp;lt;code&amp;gt;del dictionary[&amp;#039;Key&amp;#039;]&amp;lt;/code&amp;gt; to remove a dictionary key and its value rather than &amp;lt;code&amp;gt;dictionary.delete(&amp;#039;Key&amp;#039;)&amp;lt;/code&amp;gt;?  Why have a distinct &amp;lt;code&amp;gt;del&amp;lt;/code&amp;gt; command for this one activity?&lt;br /&gt;
* In Python version 3, int + int = int.  int - int = int.  int * int = int.  So what is int / int?  Nope, it is always a float; even 4 / 2 = 2.0 rather than 2.  This is inconsistent behaviour.  (In Python version 2, the result of dividing an int by an int is an int.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== WTF??? ==&lt;br /&gt;
* Create a table to play Noughts and Crosses:&lt;br /&gt;
 table = [ [&amp;quot;.&amp;quot;] * 3 ] * 3&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print(table[0],&amp;quot;\n&amp;quot;,table[1],&amp;quot;\n&amp;quot;,table[2])&lt;br /&gt;
 [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;] &lt;br /&gt;
  [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;] &lt;br /&gt;
  [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;]&lt;br /&gt;
The formatting needs fixing, but otherwise it&amp;#039;s looking good.  We&amp;#039;ve got &amp;quot;.&amp;quot; for where a &amp;quot;O&amp;quot; or a &amp;quot;X&amp;quot; can be played.  So, 1st player makes a move:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table[1][2] = &amp;quot;X&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print(table[0],&amp;quot;\n&amp;quot;,table[1],&amp;quot;\n&amp;quot;,table[2])&lt;br /&gt;
 [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;] &lt;br /&gt;
  [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;] &lt;br /&gt;
  [&amp;#039;.&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;]&lt;br /&gt;
Eh?  Why three lots of &amp;quot;X&amp;quot; in a column?  Now the second player makes a move:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table[2][0] = &amp;quot;O&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print(table[0],&amp;quot;\n&amp;quot;,table[1],&amp;quot;\n&amp;quot;,table[2])&lt;br /&gt;
 [&amp;#039;O&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;] &lt;br /&gt;
  [&amp;#039;O&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;] &lt;br /&gt;
  [&amp;#039;O&amp;#039;, &amp;#039;.&amp;#039;, &amp;#039;X&amp;#039;]&lt;br /&gt;
WTF?  Yep, the command &amp;lt;code&amp;gt;table = [ [&amp;quot;.&amp;quot;] * 3 ] * 3&amp;lt;/code&amp;gt; creates a list of 3 dots, then creates three pointers to that same list.  What on earth is the point of that?  And why doesn&amp;#039;t the first &amp;quot;[…]* 3&amp;quot; behave like the second &amp;quot;[…]* 3&amp;quot; and just create three pointers pointing at the first &amp;quot;.&amp;quot;?  This is just &amp;#039;&amp;#039;&amp;#039;stupid&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;inconsistent&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;confusing&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* Assigning a variable to another variable creates a new variable:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy = &amp;quot;Apples&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; pete = &amp;quot;Pears&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy = pete&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy&lt;br /&gt;
 &amp;#039;Pears&amp;#039;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy = &amp;quot;Bananas&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; pete&lt;br /&gt;
 &amp;#039;Pears&amp;#039;&lt;br /&gt;
BUT assigning a list to another list &amp;#039;&amp;#039;&amp;#039;does not&amp;#039;&amp;#039;&amp;#039; create a new list:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy = [&amp;quot;Apples&amp;quot;]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; pete = [&amp;quot;Pears&amp;quot;]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy = pete&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy&lt;br /&gt;
 [&amp;#039;Pears&amp;#039;]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; andy[0] = &amp;quot;Bananas&amp;quot;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; pete&lt;br /&gt;
 [&amp;#039;Bananas&amp;#039;]&lt;br /&gt;
Both &amp;lt;code&amp;gt;andy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pete&amp;lt;/code&amp;gt; are pointing at the same place in memory; changing one changes another.  This is &amp;#039;&amp;#039;&amp;#039;stupid&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;inconsistent&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;confusing&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* Another example&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; row = [1,2,3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table1 = row * 3&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table2 = [row] * 3&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table3 = [row * 3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table1&lt;br /&gt;
 [1, 2, 3, 1, 2, 3, 1, 2, 3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table2&lt;br /&gt;
 [[1, 2, 3], [1, 2, 3], [1, 2, 3]]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table3&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[1, 2, 3, 1, 2, 3, 1, 2, 3]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; row[1] = 99&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; row&lt;br /&gt;
 [1, 99, 3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table1&lt;br /&gt;
 [1, 2, 3, 1, 2, 3, 1, 2, 3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table2&lt;br /&gt;
 [[1, 99, 3], [1, 99, 3], [1, 99, 3]]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table3&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[1, 2, 3, 1, 2, 3, 1, 2, 3]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
So it is not just as simple as two variables pointing to the same place in memory; it is &amp;#039;cleverer&amp;#039; than that.  It actually remembers that &amp;lt;code&amp;gt;table2&amp;lt;/code&amp;gt; is constructed from three instances of &amp;lt;code&amp;gt;row&amp;lt;/code&amp;gt;.  And this works both ways:&lt;br /&gt;
 table2&lt;br /&gt;
 [[1, 99, 3], [1, 99, 3], [1, 99, 3]]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; row&lt;br /&gt;
 [1, 99, 3]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table2[0][1]=88&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; table2&lt;br /&gt;
 [[1, 88, 3], [1, 88, 3], [1, 88, 3]]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; row&lt;br /&gt;
 [1, 88, 3]&lt;br /&gt;
So you have to remember that when assigning a list variable to another list variable, that Python behaves differently than with other variable assignments.  And you have to also remember that whenever you change the contents of a list, the values in that list may be being used by another list somewhere else in the program without your knowledge.  What a mess.&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a=[99]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; b=[a]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a[0]=[b]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[[[...]]]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; b&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[[[...]]]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Oops.  I broke Python.&lt;br /&gt;
&lt;br /&gt;
[[Category: Python]]&lt;/div&gt;</summary>
		<author><name>Simon</name></author>
	</entry>
</feed>