Home | | Computer Science 12th Std | Defining classes

Python - Defining classes | 12th Computer Science : Chapter 10 : Python Modularity and OOPS : Python Classes and Objects

Chapter: 12th Computer Science : Chapter 10 : Python Modularity and OOPS : Python Classes and Objects

Defining classes

In Python, a class is defined by using the keyword class.

Defining classes

In Python, a class is defined by using the keyword class. Every class has a unique name followed by a colon ( : ).

Syntax:

class class_name:

statement_1

statement_2

…………..

…………..

statement_n

Where, statement in a class definition may be a variable declaration, decision control, loop or even a function definition. Variables defined inside a class are called as “Class Variable” and functions are called as “Methods”. Class variable and methods are together known as members of the class. The class members should be accessed through objects or instance of class. A class can be defined anywhere in a Python program.

Example: Program to define a class

class Sample:

x, y = 10, 20 # class variables

In the above code, name of the class is Sample and it has two variables x and y having the initial value 10 and 20 respectively. To access the values defined inside the class, you need an object or instance of the class.

 

Tags : Python , 12th Computer Science : Chapter 10 : Python Modularity and OOPS : Python Classes and Objects
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Science : Chapter 10 : Python Modularity and OOPS : Python Classes and Objects : Defining classes | Python


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.