Python Essentials Classroom Series – 18/Aug/2021

Classes and Objects

  • An object is a custom data structure containing both data (variables, called as attributes) and code (functions called methods)
  • To create a new object we need to define a class.
  • Class names should follow pascal casing (PEP-8) Refer Here
class Student:

# creating object

s1 = Student()
s2 = Student()
  • An attribute is a variable inside a class or an object. We can assign attributes during and after an object/class is created Preview

  • A method is a function in a class or object.

  • Initialization:

    • If you want to assign object attribute at creation time, we need to use special initalization method __init__()
    • Consider the below class
      class Student:
          """This class represents a Student
          def __init__(self, name) -> None:
     = name
      • Exercise: Create a python class Student which while initialization should allow to pass name and emailid
  • Quick programming intro to Inheritance Refer Here for the changeset.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin