TN Online TestSamacheer Kalvi practice

Python Classes and objects - Formula Sheet

Share this chapter: Telegram

Syntax and Rule Cheat Sheet

This chapter does not contain mathematical formulas, but the following are the critical syntax structures and rules governing Python classes and objects:

Class Definition

The standard syntax to define a class block:

class ClassName:
    class_variable = value
    def method_name(self, parameters):
        statements

Object Instantiation

The process of creating an object instance:

object_name = ClassName(arguments)

Constructor Definition

Defining an initialization constructor:

def __init__(self, parameters):
    self.instance_variable = parameter_value

Destructor Definition

Defining a destructor to release class resources:

def __del__(self):
    statements

Member Access

Accessing variables and invoking methods of an object:

object_name.variable_name
object_name.method_name()

Private Attribute Declaration

Declaring a private variable within a class:

__variable_name = value

Solved MCQs → Practice test →

More for this chapter

Book Back Questions10 textbook MCQs · solved Additional MCQs15 extra MCQs · solved Practice TestInteractive · instant score Book Back TestTest yourself on the textbook set Additional MCQ TestTest yourself on the extra set Study NotesConcepts & methods

More chapters in Computer Science

View all
1 Function 2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 5 Python -Variables and Operators 6 Control Structures 7 Python functions 8 Strings and String manipulation 9 Lists, Tuples, Sets and Dictionary 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV files 14 Importing C++ programs in Python. 15 Data manipulation through SQL 16 Data visualization using pyplot: line chart, pie chart and bar chart