xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to create a class and its object in Python
Python Online Editor
Execute Code
More Python Sample Codes
# Defining a class class Person: def __init__(self): self.Name = "" self.Age = 0 # Creating an object of Person class personObj = Person() personObj.Name = "John" # Assigning value personObj.Age = 25 # Assigning value print(personObj.Name + " is " + str(personObj.Age) + " years old.") #Another example of class # Defining Student class class Student: def __init__(self, name, gpa): #using positional parameters self.Name = name self.GPA = gpa # Creating an object of Student class with positional arguments "Alex", 3.5 studentObj = Student("Alex", 3.5) print(studentObj.Name + " earned GPA " + str(studentObj.GPA) + ".")