Lecture notes for the Introduction to Computer Science I by James Tam Return to the course web page

Example Programs: Composites

Description

Program name

Passing a whole string to a function

String1.py

Indexing the parts of a string

String2.py

Demonstrating the immutability of strings

String3.py

String slicing

String4.py

Strings as sets, test for inclusion using ‘in’)

String5.py

Strings that are repetitive sequence

String6.py

Using string functions: converting string input to numerical

String7.py

Using string functions that return modified versions of a string

String8.py

String search functions

String9.py

Version 1 of a class list problem (how not to solve the problem)

classList1.py

Version 2 of a class list problem (more appropriate solution)

classList2.py

List 'copy' (only the reference is copied and not the list data)

Copy1.py

Proper list copy (data is copied)

Copy2.py

Passing a reference to a list as a parameter (original list is modified)

Parameter1.py

Passing a reference to a list as a parameter (only the local reference is changed)

Parameter2.py

2D list: a simulated world that is randomly populated, a grid is drawn around each list element

Grid.py

List operations (concatenation and membership)

List1.py

List operation (membership)

List2.py

Simple tuple example

Tuples1.py

Dictionary operation (creation)

Dictionary1.py

Dictionary operations (deletion, checking for membership)

Dictionary2.py

Illustrating how the len function works

string_length.py

Length function operating in conjunction with lists

list_length.py