Static method

Static method can be called without creating an object or instance. Simply create the method and call it directly.

This is in a sense orthogonal to object orientated programming: we call a method without creating objects.

Related course: Complete Python Bootcamp: Go from zero to hero in Python


Demonstration of static method below. Define a class with a method. Add the keyword @staticmethod above it to make it static.

A class can contain both static and non-static methods. If you want to call non-static methods, you’ll have to create an object. The code below does not work because an object is not created:

If we create an object, we can call non-static methods:


An iteratable is a Python object that can be used as a sequence. You can go to the next item of the sequence using the next() method.

You can loop over an iterable, but you cannot access individual elements directly.
It’s a container object: it can only return one of its element at the time.

Related course: Complete Python Bootcamp: Go from zero to hero in Python


Define a dictionary and an iterable like the code below:

You can loop over the items like so:

Create an iterator to use the next method:

You cannot access elements using an index, this will raise an exception.
Iterable object types includes lists, strings, dictionaries and sets.

The demo below applies an iterator to a list:


virtualenv can create isolated Python environments.

Inside your environment you can install any module without affecting the systemwide configuration.

Imagine two Python apps of which one needs libBar 1.0 and another libBar 2.0. A virtualenv solves this problem cleverly by creating an isolated environment.

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Setup virtual environment

To create a virtual environment use the command:

where envname is your project name. If we name the project “testproject” we get this line:

This will create the folder virtualenv with these sub directories: bin, include, lib and share.

To load your virtual environment type

Your virtual environment is now activated.
The shell will show the current virtual environment is loaded.

virtualenv python

To return to the normal environment, type

You can create as many virtual environment as you want. Every project should have its own virtualenv because it needs specific modules that need not be installed system wide.

virtualenv showing modules

Study drill

Try the exercises below:


The enumerate is a built-in function that returns an enumerate object.

The call is enumerate(sequence, start=0)

The output object includes a counter like so: (0, thing[0]), (1, thing[1]), (2, thing[2]),
and so on.

As input it takes a sequence like a list, tuple or iterator. The start parameter is optional.
If the start parameter is set to one, counting will start from one instead of zero

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Enumerate object

Create a sequence and feed it to the enumerate function. This can be any type of sequence, in this example we use a list. Then we output the object.

Try the program below:

You should see this output:


The returned object can be treated like an iterator: the next method call will work:

Study drill

Try the exercises below