Python/Class

From EventScripts Community Encyclopedia



Contents

class

Python Module: core
Class: Na
Within ES2 package: yes

Description

This is a part of the core Python syntax and does not require importing a module to use

Class allows the creation of a class in python. Anything within the indentation scope after the class call is included in that class by the Python interpreter

Syntax

class <name>(<type>):
  • name: The name you choose for your class
  • type: The type of the class (where it inherits from), could be a built in type or another predefined class in your script. Generally use object

Examples

# Demonstrating class creation and what is 'in' the class and what 'isn't'
class my_class(object):
        avar = 'a class variable'
        def __init__(self):
                #this tab level is inside the __init__ function of the classs
                pass
        def newfunc(self):
                # this is a new function in the class
                pass
 
def notinclass()
        # This function is NOT included in the class
        pass

Notes

blog comments powered by Disqus