In trying to learn Python, I have used several resources. I have produced a lot of files, some of which I probably will never need again.
In this repo, I am saving my files to which I expect to return, for reference.
The tests/ directory contains trivial small files, referenced in some of my notes.
-
Use of random number to make a simple fight scene; if-elif-else; while-loop
-
10 useful built-in functions, used in examples.
-
Demo of how to create classes, with their attributes and internal functions. How the functions are called. How to pass one class into another class — in this case, making all "customers" also "people."
-
Demo of how using a different formatter produces different output.
-
How to use lambda (Python's anonymous function construct) and
map()
, a built-in function that's kind of like a for-loop in that it runs a function on each item in a list or a range. Handy! -
Things we can do with lists.
-
Demo showing how modulo (modulus) works: Test a number to see if it is prime.
-
These options can make the arguments more flexible. One option is to set a default value. Another is to say the number of arguments might vary.
-
Short program that prints all Python keywords.
-
Very basic read and write for files:
open()
,read()
,write()
,close()
. -
Split a string on a char (e.g. ",") to make a list. If the resulting list items are splittable pairs, you can use a for-loop to build a dictionary from the list.
-
Run various tests on a string to find out whether it would be okay to use it as a filename.
-
Some simple examples of error handling. Students sometimes want to use an if-statement instead, but this is better because you can catch specific types of errors. Also, use of
finally:
-
Examples of tuples. Unlike a list, a tuple is immutable.
-
Learning to use Python's turtle module.
-
Tests with copy, random, time, pickle (for saving binary data out, as from a game, and then reading it back in).
-
Examples based on a Python intro. Using for-loops to get keys, values from a dictionary is useful. Good for a fast review of basics. Also
if x in y:
-
Writing non-text data into a file as text and (awesomely) reconstituting the data back into Python objects as you read it out of the text file.
Very trivial small files to show me how something is done.
-
firstamendment.txt - dummy text file
-
My notes about these, following LPTHW ex. 37.
-
My notes about Python style (from PEP 8).