Name

class

Examples
class HLine(object):  # Class definition
  def __init__(self, ypos, stroke_color):  # Object constructor
    self.ypos = ypos
    self.stroke_color = stroke_color

  def display(self):  # Display method
    stroke(self.stroke_color)
    line(0, self.ypos, width, self.ypos)

# Declare and construct two objects (h1 and h2) of the class HLine(object):
h1 = HLine(20, 0)
h2 = HLine(50, 255)

background(127)
h1.display()
h2.display()
Description Keyword used to indicate the declaration of a class. A class is a composite of fields (data) and methods (functions that are a part of the class) which may be instantiated as objects. The first letter of a class name is usually uppercase to separate it from other kinds of variables. In Python, instance variables are accessed via the self keyword.
Syntax
class ClassName(object):
  statements
Parameters
ClassNameAny valid variable name
statementsList of statements
Related Object

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.