For 2021 - online Python 3 training - see ((here)).
Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.
Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Well House Consultants
You are on the site of
Well House Consultants
Open Source Training Courses
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
Well House Manor Resources
Object Orientation and General topics
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
C and C++ Resources
Web and Intranet Resources
Python module Y102
Python - Fundamentals
Exercises, examples and other material relating to training module Y102. This topic is presented on public courses Learning to program in Python
, Python Programming
Every programming language requires variables, assignments and operations but even these basic facilities differ from Fortran to C and from Perl to Python. This module covers these fundamental facilities in Python, as well as keyboard input, screen output, and how to add comments to yur Python.
Related technical and longer articlesPython Fast Start
|Articles and tips on this subject||updated|
|4712||A reminder of the key issues to consider in moving from Python 2 to Python 3|
1. New style classes take on the old style class format
But does it matter if you explicity inherit in Python 3??
2. print moves from being a keyword to a function
Single value tuple as parameter will work in both cases
You may also do a sys.stdout.write
3. integer ...
|4442||Mutable v Immuatble objects in Python, and the implication|
In python, "everything is an object" - well, at least everything you name, and lots of standard system things too, are!
Some object types are immutable. That means tha once they have been created, they cannot be modified and any code that looks like it modifies them in reallity produces a new object ...
|4324||Learning to program - variables and constants|
Further material from our "learning to program in ...." courses ... an introduction to variables and constants
Information - data - needs to be stored in a program between statements. Or rather it needs to be stored in the computer's memory. At the lowest of levels, that's a binary ...
|3917||BODMAS - the order a computer evaluates arithmetic expressions|
What order does a computer program use to evaluate expressions? If I write
2 + 3 * 4 + 5
does it start off, left to right ...
2 + 3 is 5
5 * 4 is 20
20 + 5 is 25
No! it does not, even though the newcomer might think that was the most natural way for ...
|3886||Formatting output - why we need to, and first Python example|
I understand that if you win the lottery in a big way, a lot of long lost relatives who have fallen on hard times will come out of the woodwork ... and if you've got a lot of brothers and sisters you might find a surprising number of nieces and nephews!
Being a generous soul, you've decided to split ...
|3551||Some terms used in programming (Biased towards Python)|
Some of the elements of your program
- typically a keyword followed by series of parameters
- a "unit" of shell / batch / Tcl programming
(You don't really have commands in Python)
Statement - an atomic operational unit of a program
- a "unit" of Python / Perl / PHP / Lua / C etc ...
|3278||Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java.|
Starting with a clean slate. Are variables initisialised, and if so, how? Even with this fundamental question, languages vary considerably.
C and C++
From my (e)mailbag ...
"""In a piece of code weâ€™ve written we declare an array, but we do not fill the elements with values, we assume (dangerous ...
|3181||Beware - a=a+b and a+=b are different - Python|
It's commonly stated the the += operator is simply a more efficient and shorter to code alternative to using a + operator and saving back to the same variable ... in other words that
original += extra
original = original + extra
do the same thing.
But - in Python at least ...
|3083||Python - fresh examples from recent courses|
During courses, I write a lot of examples in front of delegates so that the get to see both a program to perform a certain task and how that solution was reached - after all, they'll be expected to modify and write programs after the course, and just showing them the final result would only be telling ...
|2778||Learning to program in Python 2 ... and / or in Python 3|
Yesterday - "Learning to Program in Python" - and I'm now teaching the day so that it's both Python 2 and Python 3 compatible. But it's really an intro day, and we'll vary how we go for the following 3 days of the course, majoring in an appropriate direction for our group - that's a luxury we have when ...
|1461||Python - input v raw input|
If you use input, then the data you type is is interpreted as a [b]Python Expression[/b] which means that you end up with gawd knows what type of object in your target variable, and a heck of a wide range of exceptions that can be generated. So you should NOT use input unless you're putting something ...
|2442||Variable storage - Perl, Tcl and Python compared|
From Monday to Wednesday, I was teaching Python to a group of delegates at a company where I have previously taught Tcl and Expect and Perl. And this interesting diagram shows just what a contrast there is between the three languages right from the start - in terms of how data is stored into variables!
|2368||Python - fresh examples of all the fundamentals|
Some more new examples in Python - from this week's course.
From my Introduction to Python / simple example to show the power of the language, I present my example that parsed a big data (log) file and counter and sorted by number of accesses the hits from various remote hosts. A long report, ending ...
|1878||Pascals Triangle in Python and Java|
There are certain "party pieces" that I have during courses ... and on my Java Courses, a program to generate Pascal's Triangle in an array of arrays is one of them.
One of my delegates on today's Python Course suggested this as an exercise ... and here's a link to the source. Turns out to be even ...
|1448||Question on division (Java) - Also Perl, PHP, Python ...|
What's the difference between % and /?
/ returns the result of a division
% returns the remainder when you do a division.
Divide 18 by 7 you get 2, with a remainder of 4 (i.e. 4 left over).
so 18/7 give 2, and 18%7 gives 4.
And from Tcl/Tk and Expect... you can see the float v integer considerations ...
|1430||Integer v float - Python|
If you had f failures in s samples, what proportion failed? .6666666666 you might correctly say - but Python might not come up with that answer if you have two integer counts
>>> s = 6
>>> f = 4
And that gives:
Will that be better if we turn it into percentages?
Yes - ...
|956||Python security - trouble with input|
The danger of Python's input function - also known as giving away your secrets to your user.
If you're writing a Python program and asking your user for input, you should always use the raw_input function and never input. Why? Because what you type to input is interpretted through an expression and ...
|748||Getting rid of variables after you have finished with them|
If you've finished with a variable in your program, you can usually just leave it "in situe" and it will be destroyed and the memory it occupied will be released when you exit from your program. In many languages, variables within named blocks of code have an even shorter "shelf life" - by default, a ...
|633||Copying a reference, or cloning|
If you copy a variable in a program, you end up with a duplicate, right?
set second $first ... in Tcl
second=$first ... in shell
second = first ... in Python, Ruby, C and Java
$second = $first ... in Perl and PHP
Well - ALMOST right. For sure an assignment copies a variable, but where that variable ...
|328||Making programs easy for any user to start|
If you write a program in Perl, your colleague writes a program in Tcl/Tk and your company runs an open source program that's written in Python, how do your users ensure that they get the right interpretter to run the program? You certainly don't want them to have to remember to type something like:
Examples from our training material
|cli|| Running a python program without having to type in "python" every time|
|comment.py|| Commenting your program|
|const.py|| Constants in Python|
|constr.py|| Constant Strings|
|demo|| Simple first steps - prompt, read, calculate, report|
|henry|| Conversion, Coercion, and 2 forms of print|
|i2.py|| input with built in coercion|
|inout.py|| raw input|
|leadollar|| Output - with and without spacing|
|o2|| Stripping leading and trailing space|
|oper.py|| Maths operations in Python|
|pasco|| Pascals Triangle|
|pout.py|| More about print statements|
|pygo|| Deleting a variable v deleting its contents|
|repo.py|| Operator precedence in Python|
|tqs.py|| Strings several lines long|
|trimmer|| early example of formatting output|
|y102a|| Answer to end of module exercise|
|yraw|| input v raw_input|
PicturesOn a private Python course
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Variables, assignments and data types.
Operators, expressions and delimiters.
Coercion and conversion.
Screen output, keyboard input.
The print statement.
Commenting your program.
The #! line.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
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.