posts home

Introduction to OOP in Python

This serves only as an introduction to basic parts of OOP in Python 3. Defining a class We can define a class using the class keyword. We can give this class some variables and methods. 1 2 3 4 5 6 7 8 9 #!/usr/bin/env python class Foo: bar = "hello world" def print_var(self): print( f = Foo() f.print_var() hello world Notice here, that print_var takes self as a parameter, however we do not have to pass it as an argument.