<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Python_Primer</id>
	<title>Python Primer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Python_Primer"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Python_Primer&amp;action=history"/>
	<updated>2026-05-13T23:36:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Python_Primer&amp;diff=61384&amp;oldid=prev</id>
		<title>Ksolis at 08:38, 2 October 2017</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Python_Primer&amp;diff=61384&amp;oldid=prev"/>
		<updated>2017-10-02T08:38:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Python]]&lt;br /&gt;
[[File:Nobleprog.svg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;np_frontpage_header&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Python Primer&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;np_frontpage_footer&amp;quot;&amp;gt; &amp;lt;p&amp;gt;Copyright © 2015 NobleProg™. All Rights Reserved.  www.nobleprog.us&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{PB}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--__NOTOC__--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{PB}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Python Introduction=&lt;br /&gt;
*Python is an interpreted language&lt;br /&gt;
:*Compilation steps are not needed&lt;br /&gt;
::*This makes it less cumbersome&lt;br /&gt;
::*For example class files (i.e. java) are not needed&lt;br /&gt;
*Python is less complex than languages such as C++ or Java&lt;br /&gt;
:*Makes it easier to learn and use&lt;br /&gt;
:*There is a tradeoff since programs cannot be as complex&lt;br /&gt;
&lt;br /&gt;
=Python Primer=&lt;br /&gt;
==Invoking the Interpreter==&lt;br /&gt;
*The Python interpreter runs the code of a program&lt;br /&gt;
*It is in the Python (c:\Python34 on my computer) folder&lt;br /&gt;
:*The folder that was used when installing python&lt;br /&gt;
:*It is python.exe&lt;br /&gt;
*The python folder should be in the path environment variable&lt;br /&gt;
*To run the interpreter on Windows (other systems are similar) with the path set correctly&lt;br /&gt;
:*Open a command prompt&lt;br /&gt;
:*type in the command python someFileName.py&lt;br /&gt;
::*This runs the program specified&lt;br /&gt;
:*Type in python&lt;br /&gt;
::*This runs python in interactive mode (see References below)&lt;br /&gt;
&lt;br /&gt;
:*&amp;lt;big&amp;gt;References&amp;lt;/big&amp;gt;&lt;br /&gt;
:::[https://www.java.com/en/download/help/path.xml Set Environment Variables Article]&lt;br /&gt;
:::[https://docs.python.org/2/tutorial/interpreter.html# Invoking the python interpreter in interactive mode]&lt;br /&gt;
&lt;br /&gt;
==Using an IDE==&lt;br /&gt;
*Install an Integrated Development Environment&lt;br /&gt;
:*PyCharm is a good one&lt;br /&gt;
:*Eclipse has a plugin to allow coding in Python&lt;br /&gt;
*Learn how to use it&lt;br /&gt;
:*Create projects and files&lt;br /&gt;
:*Debug the projects&lt;br /&gt;
:*Run the projects&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;big&amp;gt;References&amp;lt;/big&amp;gt;&lt;br /&gt;
:::[https://www.jetbrains.com/pycharm/ PyCharm]&lt;br /&gt;
:::[http://pydev.org/ PyDev plugin for Eclipse]&lt;br /&gt;
:::[http://www.liclipse.com/ LiClipse - Eclipse with Python and other plugins]&lt;br /&gt;
&lt;br /&gt;
==Python Variables==&lt;br /&gt;
*Variables keep data i.e. integers, strings, floats&lt;br /&gt;
:*Memory locations used to store data&lt;br /&gt;
*Python does not declare variables&lt;br /&gt;
*Other languages i.e. Java do declare variables&lt;br /&gt;
*This makes Python simpler to code&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Variable declaration and use in Java:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
int integer1 = 5;&lt;br /&gt;
int integer2 = 6;&lt;br /&gt;
float float1 = 6.75;&lt;br /&gt;
String myString = &amp;quot;This is a string&amp;quot;;&lt;br /&gt;
String anotherString;&lt;br /&gt;
&lt;br /&gt;
integer1 = integer2 + 7;&lt;br /&gt;
integer2++;&lt;br /&gt;
anotherString = myString + &amp;quot; now adding to string&amp;quot;; integer2++;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Variable declaration and use in Python:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
variable1 = 5&lt;br /&gt;
variable2 = &amp;quot;This is a string&amp;quot;&lt;br /&gt;
&lt;br /&gt;
variable1 = variable2 + &amp;quot; now adding to string&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
*Variable types are assigned when data is put into them&lt;br /&gt;
*Variables can be moved between types&lt;br /&gt;
*The types are:&lt;br /&gt;
:*numbers - integer, long, float, complex&lt;br /&gt;
:*String - a contiguous set of characters&lt;br /&gt;
:*List - items of various types, enclosed in braces [], separated by commas&lt;br /&gt;
:*Tuple - items of various types, enclosed in parentheses, separated by commas, read-only&lt;br /&gt;
:*Dictionary - contains name values pairs, a hash table&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;big&amp;gt;&amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;Hands on Exercise&amp;lt;/span&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
:::*Start PyCharm which we installed in a prior step&lt;br /&gt;
:::*Using PyCharm create a project called &amp;quot;Python Primer&amp;quot;&lt;br /&gt;
:::*Create a new file called variables a py extension will be added&lt;br /&gt;
:::*Edit the file variables.py in PyCharm&lt;br /&gt;
:::*Create an integer, a float, and a String as variables in the file&lt;br /&gt;
:::*Print out the variables using print(theVariableName)&lt;br /&gt;
:::::Note that the parentheses are required for Python 3 and above&lt;br /&gt;
:::::Print is now a function it was a statement&lt;br /&gt;
:::*Try various operators on the integers and floats + - / * % // **&lt;br /&gt;
:::*Try concatenating strings&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
*The standard arithmetic operators are:&lt;br /&gt;
::+ addition&lt;br /&gt;
::- subtraction&lt;br /&gt;
::\* multiplication&lt;br /&gt;
::/ division&lt;br /&gt;
::% modulus - gives the remainder of division&lt;br /&gt;
::// integer division gives the whole number (or rounded down)&lt;br /&gt;
::\*\* exponents&lt;br /&gt;
&lt;br /&gt;
*Comparison operators&lt;br /&gt;
::== example x == y -- is x equal to y (gives true or false)&lt;br /&gt;
::!= example x != y -- is x not equal to y (gives true or false)&lt;br /&gt;
::&amp;lt;&amp;gt; example x &amp;lt;&amp;gt; y -- same as above is x not equal to y&lt;br /&gt;
::&amp;gt; example x &amp;gt; y -- is x greater than y&lt;br /&gt;
::&amp;lt; example x &amp;lt; y -- is x less than y&lt;br /&gt;
::&amp;gt;= example x &amp;gt;= y -- is x greater than or equal to y&lt;br /&gt;
;:&amp;lt;= example x &amp;lt;= y -- is x less than or equal to y&lt;br /&gt;
&lt;br /&gt;
*Logical Operators&lt;br /&gt;
::and example x and y -- both x and y must be true to give true&lt;br /&gt;
::or example x or y -- either x or y must be true to give true&lt;br /&gt;
::not example not(x or y) -- reverses the condition in the parentheses&lt;br /&gt;
*String operators&lt;br /&gt;
::print (str)          # Prints complete string&lt;br /&gt;
::print (str[0])       # Prints first character of the string&lt;br /&gt;
::print (str[2:5])     # Prints characters starting from 3rd to 5th&lt;br /&gt;
::print (str[2:])      # Prints string starting from 3rd character&lt;br /&gt;
::print (str * 2)      # Prints string two times&lt;br /&gt;
::print (str + &amp;quot;TEST&amp;quot;) # Prints concatenated string&lt;br /&gt;
&lt;br /&gt;
*List operators&lt;br /&gt;
&lt;br /&gt;
::list = [ &amp;#039;abcd&amp;#039;, 786 , 2.23, &amp;#039;john&amp;#039;, 70.2 ]&lt;br /&gt;
::tinylist = [123, &amp;#039;john&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
::print (list)          # Prints complete list&lt;br /&gt;
::print (list[0])       # Prints first element of the list&lt;br /&gt;
::print (list[1:3])     # Prints elements starting from 2nd till 3rd &lt;br /&gt;
::print (list[2:])      # Prints elements starting from 3rd element&lt;br /&gt;
::print (tinylist * 2)  # Prints list two times&lt;br /&gt;
::print (list + tinylist) # Prints concatenated lists&lt;br /&gt;
&lt;br /&gt;
*Dictionary Operators&lt;br /&gt;
&lt;br /&gt;
::dict = {}&lt;br /&gt;
::dict[&amp;#039;one&amp;#039;] = &amp;quot;This is one&amp;quot;&lt;br /&gt;
::dict[2]     = &amp;quot;This is two&amp;quot;&lt;br /&gt;
&lt;br /&gt;
::tinydict = {&amp;#039;name&amp;#039;: &amp;#039;john&amp;#039;,&amp;#039;code&amp;#039;:6734, &amp;#039;dept&amp;#039;: &amp;#039;sales&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::print (dict[&amp;#039;one&amp;#039;])       # Prints value for &amp;#039;one&amp;#039; key&lt;br /&gt;
::print (dict[2])           # Prints value for 2 key&lt;br /&gt;
::print (tinydict)          # Prints complete dictionary&lt;br /&gt;
::print (tinydict.keys())   # Prints all the keys&lt;br /&gt;
::print (tinydict.values()) # Prints all the values&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;big&amp;gt;&amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;Hands on Exercise&amp;lt;/span&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
::*Use the documentation of lists at [http://www.tutorialspoint.com/python/python_lists.htm Python Lists] for this exercise&lt;br /&gt;
::*Create several Lists and use the following List operations, functions and methods&lt;br /&gt;
:::*List access operations list[0], list[1:5], to print list values&lt;br /&gt;
:::*Update a list value using list[someIntegerIndex] = value -- then print the list&lt;br /&gt;
:::*Delete a list value with del list[someIntegerIndex] -- then print the list&lt;br /&gt;
:::*Find and print the length of the list&lt;br /&gt;
:::*Use the built-in function min to find the minimum value in the list and print it&lt;br /&gt;
:::*Append a new value to the list&lt;br /&gt;
:::*Insert a new value into the list at location 2&lt;br /&gt;
:::*explain what pop does to the list and print a value that has been popped from the list&lt;br /&gt;
&lt;br /&gt;
:References&lt;br /&gt;
:::[http://www.tutorialspoint.com/python/python_basic_operators.htm Python Operators]&lt;br /&gt;
&lt;br /&gt;
==Python Syntax==&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Indentation&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
*Indentation in Python indicates code blocks rather than beginning and ending delimiters&lt;br /&gt;
::For example in Java code blocks are delimited by braces i.e. {}&lt;br /&gt;
*All statements in a block must have the same indentation&lt;br /&gt;
::The default indentation is four spaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Identifier naming convention&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt; (taken from TutorialsPoint.com):&lt;br /&gt;
*Class names start with an uppercase letter and all other identifiers with a lowercase letter.&lt;br /&gt;
*Starting an identifier with a single leading underscore indicates by convention that the identifier is meant to be private.&lt;br /&gt;
*Starting an identifier with two leading underscores indicates a strongly private identifier.&lt;br /&gt;
*If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Multiline Statements&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt; (taken from TutorialsPoint.com)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
total = item_one + \&lt;br /&gt;
        item_two + \&lt;br /&gt;
        item_three&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Use of Quotes&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
*Strings in Python can use single, double, or triple quotes&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
string1 = &amp;#039;This is a string&amp;#039;&lt;br /&gt;
string2 = &amp;quot;This is a string&amp;quot;&lt;br /&gt;
string3 = &amp;#039;&amp;#039;&amp;#039;This is a&lt;br /&gt;
multiline string&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
string4 = &amp;quot;&amp;quot;&amp;quot;This is also a&lt;br /&gt;
multiline string&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Comments&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*the pound sign/hash mark &amp;quot;#&amp;quot; is used for single line comments&lt;br /&gt;
*Three single or double quotes are used for multiline comments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
#This is a single line comment&lt;br /&gt;
#This is a second single line comment&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;This is&lt;br /&gt;
a multiline comment&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;This is also&lt;br /&gt;
a multiline comment&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Multiple Statement on a Single Line&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
*use semicolons as the delimiter between statements&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
a = b+1; c = d + 2; print(str(a))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Control Structures==&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;if statement&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt; - a conditional statement that can have an else clause&lt;br /&gt;
:*note that the sub-statements of the if statement are indented&lt;br /&gt;
:*the normal default for indenting is four spaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
a = 10&lt;br /&gt;
if (a == 10):&lt;br /&gt;
    print(&amp;quot;In if statement&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
a = 10&lt;br /&gt;
if (a == 10):&lt;br /&gt;
    print(&amp;quot;In if statement&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;In else statement&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;while loop&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt; - a loop that continues until the loop condition has been satisfied&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
a = 10&lt;br /&gt;
while (a &amp;lt; 15):&lt;br /&gt;
    print(&amp;quot;in while loop&amp;quot;)&lt;br /&gt;
    a += 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*while loop with else statement&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
a = 10&lt;br /&gt;
while (a &amp;lt; 15):&lt;br /&gt;
    print(&amp;quot;in while loop&amp;quot;)&lt;br /&gt;
    a = a + 1&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;while loop has ended&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;for loop&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
::the general form of the for loop is&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
for iterating_var in sequence:&lt;br /&gt;
    statements(s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
::Where iterating_var is the name of the variable &lt;br /&gt;
:::that represents the next item in the sequence to be&lt;br /&gt;
:::used in the statements of the for loop&lt;br /&gt;
&lt;br /&gt;
*An example of a sequence and a for loop that iterates through the sequence&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
animals = [&amp;#039;dog&amp;#039;,&amp;#039;cats&amp;#039;,&amp;#039;moose&amp;#039;,&amp;#039;deer&amp;#039;,&amp;#039;bear&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
for theAnimal in animals:&lt;br /&gt;
    print(&amp;quot;the animal is a &amp;quot; + theAnimal)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*An example of a sequence and an iteration using the index in the list&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
animals = [&amp;#039;dog&amp;#039;,&amp;#039;cat&amp;#039;,&amp;#039;moose&amp;#039;,&amp;#039;deer&amp;#039;,&amp;#039;bear&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
for index in range (len(animals)):&lt;br /&gt;
    print(&amp;quot;Using an index the animal is a &amp;quot; + animals[index])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;Hands on Exercise&amp;lt;/span&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
*Create a simple program using PyCharm that has a while loop and an if else statement&lt;br /&gt;
*The program will do the following&lt;br /&gt;
:::The while loop will loop 10 times.&lt;br /&gt;
:::The if else statements will be in the while loops code block&lt;br /&gt;
:::The if else statements will print out &amp;quot;In the if statement&amp;quot; for the first 5 iterations&lt;br /&gt;
:::The if else statements will print out &amp;quot;In the else statement&amp;quot; for the last 5 ieterations&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
*A function is a piece of reusable code&lt;br /&gt;
::Generally it performs an identifiable action that can be reused&lt;br /&gt;
:::For example opening, writing to, or closing a file&lt;br /&gt;
::It provides modularity for the code making it easier to understand&lt;br /&gt;
::There are standard functions provided with Python&lt;br /&gt;
::New functions can be defined by programmers (user-defined functions)&lt;br /&gt;
&lt;br /&gt;
*How to define a function&lt;br /&gt;
::Functions begin with the keywork def, followed by the function name, and then a set of parentheses ()&lt;br /&gt;
::Input parameters are placed within the parentheses ()&lt;br /&gt;
::The first statement can be an optional documentation string (docstring)&lt;br /&gt;
::The code block starts with a colon : and is indented&lt;br /&gt;
&lt;br /&gt;
*Example of a Function&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:khaki&amp;quot;&amp;gt;&lt;br /&gt;
def theFunctionName(parameters):&lt;br /&gt;
   &amp;quot;function_docstring&amp;quot;&lt;br /&gt;
   function statements&lt;br /&gt;
   return [expression]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Built-in and Standard Library Functions==&lt;br /&gt;
&lt;br /&gt;
There are a number of functions that are built-in in Python&lt;br /&gt;
::See the Python Documentation on Build-in Functions in the References below&lt;br /&gt;
::These are part of the Standard Library&lt;br /&gt;
There are also a number of other modules in the standard library&lt;br /&gt;
::These give solutions to many everyday programming problems&lt;br /&gt;
&lt;br /&gt;
*Build-in Functions can be called directly in the code&lt;br /&gt;
::Example of using Built-in Functions&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
f = open(&amp;#039;workfile&amp;#039;, &amp;#039;w&amp;#039;)&lt;br /&gt;
f.write(&amp;quot;this is the file output&amp;quot;)&lt;br /&gt;
f.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Standard Library functions must be imported&lt;br /&gt;
::Example of using Standard Library Functions&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
from math import sqrt&lt;br /&gt;
&lt;br /&gt;
a = sqrt(24)&lt;br /&gt;
print (a)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;big&amp;gt;References&amp;lt;/big&amp;gt;&lt;br /&gt;
::[https://docs.python.org/3/library/functions.html Built-in Functions]&lt;br /&gt;
::[https://docs.python.org/3/library/ Standard Library Including Built-in Functions]&lt;br /&gt;
&lt;br /&gt;
==PythonScope==&lt;br /&gt;
*A Variable&amp;#039;s scope&lt;br /&gt;
::Python has only function, global, and class scope.&lt;br /&gt;
::It does not have block scope&lt;br /&gt;
:::For example a variable first used in a for loop can be seen outside the for loop&lt;br /&gt;
:::In many other languages such as Java, C++, and C a variable declared in a block has block scope&lt;br /&gt;
&lt;br /&gt;
*Function scope vs global scope&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
globalVar = &amp;quot;this string is global&amp;quot; #creates a global variable&lt;br /&gt;
&lt;br /&gt;
def anotherFunction ()&lt;br /&gt;
    globalVar = &amp;quot;this string is local&amp;quot; #creates a variable local to the function&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Importing External Modules==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;The import statement&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*Bring the functions within a file into the program&lt;br /&gt;
&lt;br /&gt;
Example of code import&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
Assume that the file importFunctions.py has the following code&lt;br /&gt;
&lt;br /&gt;
def print_value(parameter):&lt;br /&gt;
    print(&amp;quot;the value is &amp;quot; + parameter)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
To use this code in another file it must imported then used&lt;br /&gt;
&lt;br /&gt;
#import the functions from importFunctions&lt;br /&gt;
import importFunctions&lt;br /&gt;
&lt;br /&gt;
#use the print_value function&lt;br /&gt;
importFunctions.print_value(&amp;quot;Print This String&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;The from import statement&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*Bring the functions within a file into the program&lt;br /&gt;
*Allow the use of the functions without the leading filename&lt;br /&gt;
&lt;br /&gt;
Example of the from import statement&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
Assume that the file importFunctions.py has the following code&lt;br /&gt;
&lt;br /&gt;
def print_value(parameter):&lt;br /&gt;
    print(&amp;quot;the value is &amp;quot; + parameter)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
To use this code in another file it must imported then used&lt;br /&gt;
&lt;br /&gt;
#from import the functions&lt;br /&gt;
from importFunctions import print_value&lt;br /&gt;
&lt;br /&gt;
#use the print_value function without the leading filename&lt;br /&gt;
print_value(&amp;quot;Print This String&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object Oriented Classes==&lt;br /&gt;
*Python has classes which makes it object oriented&lt;br /&gt;
::Note that it also has functions so it is also a functional language&lt;br /&gt;
*Overview of Object Oriented Programming (OOP)&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:khaki&amp;quot;&amp;gt;&lt;br /&gt;
Class - a user defined template for objects.  Contains both variables and methods.&lt;br /&gt;
        Classes allow libraries of well tested self contained code to be distributed.&lt;br /&gt;
        Each of these self contained units is a class.&lt;br /&gt;
Class Variable - In Python it is a variable that is shared by all instances of a class&lt;br /&gt;
                 Objects are instances of classes.&lt;br /&gt;
Data Member - A class variable or instance variable that holds data&lt;br /&gt;
Functions Overloading - A set of functions of the same name with varying parameter types.&lt;br /&gt;
                        Each function can have different code&lt;br /&gt;
Instance Variable - a variable defined within a method of a class.  Variables defined&lt;br /&gt;
                    outside of the classes methods are class variables (see above).&lt;br /&gt;
Inheritance - A class will inherit the methods of a class from which it is derived.&lt;br /&gt;
              See the section below on inheritance&lt;br /&gt;
Instance - A object that has been created from a class template.  It is an object of&lt;br /&gt;
           that class.&lt;br /&gt;
Instantiation - The creation of an object from a class template&lt;br /&gt;
Method - A special type of function that belongs to and is coded within a class&lt;br /&gt;
Object - A unique instance of a class.  An object has both data members and methods.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Class Definitions===&lt;br /&gt;
*The form of a class definition is as follows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:khaki&amp;quot;&amp;gt;&lt;br /&gt;
class ClassName&lt;br /&gt;
   classData = &amp;quot;this could be any data&amp;quot;&lt;br /&gt;
   def __init__(self):&lt;br /&gt;
    self.someData = []&lt;br /&gt;
   def someFunction(self, parameter1, parameter2):&lt;br /&gt;
       statement1&lt;br /&gt;
       statement2&lt;br /&gt;
       ...&lt;br /&gt;
       return returnValue&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
**self is not a keyword it is just an indication that the first argument passed into a function is a reference to the object (it is just called self for convenience).&lt;br /&gt;
**The function __init__ is the constructor for the class that runs when a class instance is created&lt;br /&gt;
**The statement self.someDate create a list that belongs to the instance object&lt;br /&gt;
**The statement classData = &amp;quot;this could be any data&amp;quot; creates a class variable shared across instance objects of the class&lt;br /&gt;
&lt;br /&gt;
===Class Variable Scope===&lt;br /&gt;
*Class variables have a scope across all instance objects of the class&lt;br /&gt;
*Instance variables have scope within an instance object of the class&lt;br /&gt;
:::Instance variable are defined within class methods (functions in the class)&lt;br /&gt;
&lt;br /&gt;
See Reference [https://docs.python.org/2/tutorial/classes.html Python Tutorial on Classes]&lt;br /&gt;
::Read the section on Namespaces for a better understanding of variable scope&lt;br /&gt;
::Read the section on Class and Instance Variables for a better understanding&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Example of a class&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
class Dog:&lt;br /&gt;
    kind = &amp;#039;canine&amp;#039;         # class variable shared by all instances&lt;br /&gt;
    def __init__(self, name):&lt;br /&gt;
        self.name = name    # instance variable unique to each instance&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Use of the class to understand variable scope&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
dog1 = Dog(&amp;#039;fido&amp;#039;)&lt;br /&gt;
dog2 = Dog(&amp;#039;Buddy&amp;#039;)&lt;br /&gt;
print(dog1.name)    # will give name of Fido which is an instance variable&lt;br /&gt;
print(dog1.kind)    # will give a kind of canine which is a class variable&lt;br /&gt;
print(dog2.name)    # will give a name of Buddy which is an instance variable&lt;br /&gt;
print(dog2.kind)    # will give a kind of canine which is a class variable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Note that there is no concept of public and private variables&lt;br /&gt;
::For example java has public and private keywords, Python does not&lt;br /&gt;
::There is a convention that states:&lt;br /&gt;
:::Variables and functions that begin with an underscore (i.e. _variable1)&lt;br /&gt;
:::should be treated as private and not public&lt;br /&gt;
&lt;br /&gt;
===Class Inheritance===&lt;br /&gt;
*A class can inherit methods and data from other classes&lt;br /&gt;
*The definition of the class looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue;background-color:lightgrey&amp;quot;&amp;gt;&lt;br /&gt;
class DerivedClassName(BaseClassName):&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, etc.):&lt;br /&gt;
         statement1&lt;br /&gt;
         ...&lt;br /&gt;
&lt;br /&gt;
    def function1()&lt;br /&gt;
        statement1&lt;br /&gt;
        ...&lt;br /&gt;
        return somevalue&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: the class will inherit the attributes of BaseClassName&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
:[https://www.python.org/ Python main site]&lt;br /&gt;
:[https://docs.python.org/3/ Phython.org Documentation]&lt;br /&gt;
:[https://wiki.python.org/moin/BeginnersGuide/Programmers Beginners Programming Guides]&lt;br /&gt;
:[http://www.tutorialspoint.com/python/index.htm TutorialsPoint.com Python Tutorial]&lt;/div&gt;</summary>
		<author><name>Ksolis</name></author>
	</entry>
</feed>