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

Dictionaries

A Python dictionary is an implementation of what you may know as a hash table or associative array. A dictionary consists of a collection of key-value pairs. When you query…

Continue Reading Dictionaries

Sets

The set data type in Python implements most of the operations from mathematical sets. The most common representation of sets in mathematics uses Venn diagrams (overlapping circles) which I'm assuming…

Continue Reading Sets

Tuples

A Python tuple is an ordered, immutable set of data items. By¬†ordered, we mean that the items in a tuple are stored in a definite order, not necessarily that they…

Continue Reading Tuples

List comprehension

[latexpage] We've seen how to create and manipulate lists in Python. There is a special way of creating a list that is concise and powerful. This is¬†list comprehension. The syntax…

Continue Reading List comprehension

Lists: the basics

The Python list is a powerful data type with a lot of functionality, so we'll cover it in several posts. Here we start with some of its basic properties. First,…

Continue Reading Lists: the basics