After some try / except as a teacher, I chose to stick to something like:
(starting from nothing, adjust to their level)
- Shortly, what is Python and what you can do with it. Skip the speech on technical stuff and focus on what they want to do : music, GUI, Web site, renaming files, etc.
- Installing Python, running the interpreter. If you can, use iPython.
- Variables, basic strings and
print()
.
- Int and types (including type errors and casting).
- Basic calculus. Show them
1 / 0
, 10 / 3
but don't bother them with details.
- Putting calculus results in variables.
- Using variables in calculus.
- String formating with
%
. Show only "%s", it's enough and always works. Always use a tuple (with an ending coma), even if it contains only one item.
- Lists, indexing, slicing and common errors. Then show tuples as frozen lists (and casting). Show that then can contain each others. Make them work on that until they master it perfectly: this is very, very important.
- Dictionaries, with common errors. Nesting with tuples and lists. Insist on the last point.
For
loop on strings, then lists, then tuples, then dictionaries.
For
loop on nested types. Be nasty. Take your time. Knowing that part well changes everything.
- Dictionary
items()
, values()
and keys()
.
- Reading files using
for
, including IOErrors
.
- Writing files.
- Using methods. Use a string as an example showing
strip()
, lower()
, split()
, etc. Don't explain OOP, just how to use a method. Use the world "method" a lot from now.
- Creating a module file and using it. One module only. Everything in it.
- Functions (only with
return
, no print()
. Forbid print()
in functions).
- Function parameters.
- Named parameters.
- Default value parameters.
Try
/ Except
and exceptions.
Import
and creation of your own directory modules. Show all the special cases (it takes way more time to explain it than you think).
- Demonstrate some standard modules (but don't spend too much time on it, it's just to show): datetime, string, os and sys. Avoid abstract stuffs like itertools, they are a coder dream but a student nightmare.
After that you can bring OOP on the table, but it a bit more complicated. Use strings, lists and files to introduce the notion of object. When they got it, start with classes. Then may the force be with you :-)
It is tempting to use print
in functions to show how it works, and even more tempting to use raw_input
. You should avoid it at all cost. The first one makes it very difficult to bring the concept of a "returned value", the second hides the real flow of a program and students have a hard time to understand that you need to chain functions, not ask the user for every value you need.
Generally, choose one method that works for something and stick to it. Don't show alternative ways. E.g:
Show only string formating using %
, and ignore +
and ,
. You can always add a little "going further" block in your lecture material for the ones who want to know more. Show only for
and not while
. You can code almost 90% of Python programs without while
. Avoid +=
. Don't show that you can multiply strings/lists/dict with ints. This is not wrong, but will lead them to misconception. You need them focused on the main concepts.
Don't show sets. Sets are very useful but rarely used. Encourage them to code at home and to ask you if they can't solve a problem. In that case show sets if they are the solution. Knowing sets take times and student brain resources that could be used for something more often used. They will have plenty of time to learn new tools later, without you: focus on what is hard or time consuming to learn alone.
Same goes for enumerate
. Students with a C or a Java background will use indexes to loop instead of for
if you give them enumerate
. For similar reasons, keep len
, fd.read
, fd.realines
and range
for one of the last courses entitles "advanced python" if you have any time for it.
Don't even think about generators, metaclasses and decorators. These can be apprehended by very few students, even after months of practice. List comprehensions, with
and ternary operations can be brought in some of the last courses if you feel your students are smart arses.
Eventually, enforce good practices arbitrarily. PEP8 formating, good architecture, name conventions, no immutable default parameters, etc. They just can't know about it right now. Don't bother, you are the teacher, you have the right to say "this is just how it is" from time to times.
Oh, and they will be better programmers if they don't start by learning things like bytecode, recursion, assembly, complexity, bubble sort, stack, implementation details, etc. You waste time teaching this to somebody that can't code a decent Python program, he just can't see what's this is all about. Practice is your best tools to bring theory. And again, they will learn everything else by them-self later if you prepare them correctly, so prioritize and and don't be afraid to skip concepts, even simple/important ones.