What is a Class? How do you create it in Python?
What is a Class? How do you create it in Python?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
Objects are an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes. Classes are essentially a template to create your objects.
class MyClass:
variable = “blah”
def function(self):
print(“This is a message inside the class.”)
myobjectx = MyClass()
Now the variable “myobjectx” holds an object of the class “MyClass” that contains the variable and the function defined within the class called “MyClass”. For more info you can use this best essay to having a wonderful assistant in writings.
Python is an Object Oriented language and provide all the standard features of Object Oriented Programming.
Example of Class
class studentInfo:
def displayData(self, name ):
print "your name is: ", name
fn1 = studentInfo()
fn2 = studentInfo()
fn1.displayData("Aviance")
fn2.displayData("Ambar")
Output of the program:
your name is: Aviance
your name is: Ambar
vote_up