Utilizor
Contact Us

Python Classes/Objects

Object-Oriented Programming.

Examples

Create Class

Defining a class and creating an object.

class MyClass:
  x = 5

p1 = MyClass()
print(p1.x)

The __init__() Function

Initializing object properties.

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p1 = Person("John", 36)

print(p1.name)
print(p1.age)

Test Your Knowledge

Python Quiz

No quiz available for this topic yet.