Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact

New telephone system - working a day early.
01225 708225 (phone) and 01225 899360 (fax) again ;-)
Upcoming U.K. Python courses ...
Learning to program in Python
Python Programming

Tips and short articles on this subject
Passing a variable number of parameters in to a function / method
Program for reliability and efficiency - do not duplicate, but rather share and re-use
Optional and named parameters to Python functions/methods
Python - access to variables in the outer scope
Global and Enable - two misused words!
Good example of recursion in Python - analyse an RSS feed
Sample code with errors in it on our web site
Optional parameters to Python functions
Multiple returns from a function in Python
Conversion of OSI grid references to Eastings and Northings
Dynamic code - Python
Optional and named parameters in Python
What to do with a huge crop of apples
Anonymous functions (lambdas) and map in Python
Sharing variables with functions, but keeping them local too - Python
Global - Tcl, PHP, Python
Python Script - easy examples of lots of basics
Returning multiple values from a function (Perl, PHP, Python)
A better alternative to cutting and pasting code
Function / method parameters with * and ** in Python
It's the 1st, not the 1nd 1rd or 1th.
Sludge off the mountain, and Python and PHP
Python - A list of methods
Recursion in Python
Python - function v method
Dynamic functions and names - Python
Do not duplicate your code
Cottage industry or production line data handling methods
Python modules. The distribution, The Cheese Shop and the Vaults of Parnassus.
Python - block insets help with documentation
Python's Generator functions
Difference between import and from in Python
What is a callback?
Code and code maintainance efficiency
Call by name v call by value
Lambdas in Python
Python generator functions, lambdas, and iterators
Distance Learning
Variable Scope
Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Python module Y105
Functions, Modules and Packages
Exercises, examples and other material relating to training module Y105. This topic is presented on public courses Learning to program in Python, Python Programming

Python Programming - The fundamentals in depth, and an introduction to applications such as GUI design and Data Munging. This course starts at the fundamentals ...
http://www.wellho.net/course/ypfull.html  [course]
#!/usr/local/bin/python # Variable scope first = 1 def one(): "Double a global variable, return it + 3." global first first ...
http://www.wellho.net/resources/ex.php4?item=y105/locvar.py  [code sample]
Learning to Program in Python - The fundamentals in depth, and an introduction to applications such as GUI design and Data Munging. This course starts ...
http://www.wellho.net/course/ylfull.html  [course]
I'm not a great advocate of recursion - pieces of code that call themselves; most of the examples that I see in books are "training examples" that are ...
http://www.wellho.net/mouth/912_Recu ... ython.html  [short article]
Function in PHP and Python and subs in Perl can only return one "thing" - one item, one object. But all three languages allow that returned item to be ...
http://www.wellho.net/mouth/1202_Ret ... thon-.html  [short article]
When you write a program, you should split your code down into a series of named blocks, each of which performs a single logical action. Blocks will ...
http://www.wellho.net/mouth/561_Pyth ... tions.html  [short article]
What's the difference between a function and a method? A function is a named piece of code that performs an operation, and a method is a function with ...
http://www.wellho.net/mouth/900_Pyth ... ethod.html  [short article]
Python's "import" loads a Python module into its own namespace, so that you have to add the module name followed by a dot in front of references to any ...
http://www.wellho.net/mouth/418_Diff ... ython.html  [short article]

In Python, blocks of code can be named. Such named blocks of code can be run from elsewhere in your program, and are known as functions. A module is a text file that contains a number of functions and other items, and a package is a group of related modules.

This topic is presented on public courses Learning to program in Python, Python Programming

Examples from our training material
acsh2   Dynamic function definition
cardy   Main program - methods and attributes from a module
colin.py   A tiny module
dfg   Using a generator to process a big file
dream   Good structure of named blocks of code
electric.py   a generator function - carries on where it left off at previous call
extrastep.py   importing a name from a module into the current namespace
f1   more options with modules and functions
fat.py   A second program that uses shared functions in mod2.py
ffx   Dynamic function definition
flook.py   Program to use a module and the attributes of its functions
fun.py   definition and use of a function
gen   A generator - two code branches both live
gen2   Using a generator function to provide an iteration
gen_control   No using a generator - each runs to completion
genex   Generator v regular function
gubbins.py   A bunch of functions in a module
local.py   File of functions to be loaded by other examples
locvar.py   Local and global variables
m1   map to transform and filter to select from a list
mapfunc.py   Use of the map function to transform a list
mod2.py   A module with doc strings and attributes defined
mod_demo.py   Program that uses the module in local.py
mutton   Anonymous varaibles and subs and lambdas
myne.py   Module with documentation string and test harness
mystuff.py   functions, statics, test code, doc strings ...
noa   Mandatory, optional, ordered and named parameters
params.py   Optional parameters, and variable number of parameters
passenger   Calling program - sample answer with separate module for functions
poc.py   Scope of variables - some samples
qv2   Example that uses mystuff.py
qv3   alternative example using mystuff.py
recur.py   Recursion - when a function calls itself
sheep.py   A Lambda function - one line function definition
silksheets.py   Functions that we'll share between applications
slumbermore   Good structure of named blocks of code
snoresleep   A further Good structure of named blocks of code
sweetdream   Another example of a module reuse
sysdemo.py   use of a standard module (sys)
tax.py   functions to work out tax and net from gross
taxcalcs.py   Collecting function parameters
taxi   Exercise answer - net and tax from gross amount
yf   Using a generator
yum   Brining in elements from a namespace
Pictures
Studious group during a practical
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from http://www.training-notes.co.uk.
Topics covered in this module
Def and parameters. Default parameters.
return statments.
Variable scope and namespaces.
Global variables.
lambdas.
Doc strings.
Generator functions and yield.
from and import.
Built in and user defined modules.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre. Also available is the Opentalk Forum for discussion of technical questions.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2010: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 0800 043 8225 or 01225 708225 • FAX: 01225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho