Writing and reading text files

Writing and reading text files in Python is fairly straightforward. It's easiest to illustrate the process with an example. Here is some code that generates the 52 cards in a…

Continue Reading Writing and reading text files

Overloading comparison operators

[latexpage] Overloading the six comparison operators works in a similar way to the overloading of arithmetic operators. The operators and their associated methods are: Default behaviour Before we try overloading…

Continue Reading Overloading comparison operators

Encapsulation and private data

Programmers used to other object oriented languages such as C++, C# or Java will be familiar with the idea of┬áprivate data fields and methods within a class. These private fields…

Continue Reading Encapsulation and private data

Classes: definition and constructor

Although nothing we've done so far might suggest it, Python is actually a fully object-oriented language. Pretty well everything in a Python program is implemented as an object. From primitive…

Continue Reading Classes: definition and constructor

Strings and formatting

A string in Python is a sequence of Unicode characters. Defining strings A string can be defined as an immutable object by giving the character sequence between a pair of…

Continue Reading Strings and formatting