O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes

A class consists of data and the functions that act on that data. In classes, functions are referred to as methods. A way to understand classes is to think of them as functions with multiple entry points. In this way they provide data encapsulation.

You define a class with the class keyword.

class class_name:
  class_attributes

Classes can have many attributes. These attributes can be variables or definitions of either functions or other classes. For example, the definition of the class chapter has three variable attributes: number_of_pages, title, and toc.

class chapter:
        number_of_pages = 20
        title = "Organizing your program"
        toc = ["Introduction", "Modules", "Functions", "Packages", "Classes"]

Notice that the class attributes are indented, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required