Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

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 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 articles
Python Fast Start

Articles and tips on this subjectupdated
4712A 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 ...
2016-10-30
 
4442Mutable 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 ...
2015-02-24
 
4324Learning to program - variables and constants
Further material from our "learning to program in ...." courses ... an introduction to variables and constants variable basics 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 ...
2014-11-22
 
3917BODMAS - 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 ...
2012-11-10
 
3886Formatting 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 ...
2012-10-13
 
3551Some terms used in programming (Biased towards Python)
Some of the elements of your program Command - 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 ...
2011-12-17
 
3278Do 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 ...
2011-05-05
 
3181Beware - 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 and   original = original + extra do the same thing. But - in Python at least ...
2011-02-24
 
3083Python - 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 ...
2010-12-13
(longer)
2778Learning 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 ...
2010-05-25
 
1461Python - 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 ...
2010-02-28
 
2442Variable 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! In ...
2009-10-08
 
2368Python - 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 ...
2009-08-23
(longer)
1878Pascals 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 ...
2008-11-13
 
1448Question on division (Java) - Also Perl, PHP, Python ...
Q: What's the difference between % and /? A: / 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 ...
2008-09-15
(short)
1430Integer 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: >>> f/s 0 Will that be better if we turn it into percentages? >>> f*100/s 66 Yes - ...
2007-11-12
(short)
956Python 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 ...
2006-11-30
 
748Getting 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 ...
2006-06-09
 
633Copying 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 ...
2006-06-09
 
328Making 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: perl ...
2006-06-05
 
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
Pictures
On a private Python course
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 [here].
Topics covered in this module
Variables, assignments and data types.
Variables.
Data Types.
Strings.
Operators, expressions and delimiters.
Delimiters.
Coercion and conversion.
Screen output, keyboard input.
The print statement.
keyboard input.
Commenting your program.
The #! line.
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 Ruby, Lua, 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.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/Y102.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat