Posts

Showing posts with the label Module

Class & Function

  In Python, a class is a blueprint for creating objects, which are instances of the class. A class defines the attributes (variables) and methods (functions) that an object will have. You can think of a class as a template or a set of instructions for creating objects. Here is an example of a class in Python: python Copy code class Person : def __init__ ( self, name, age ): self.name = name self.age = age def say_hello ( self ): print ( f"Hello, my name is {self.name} and I am {self.age} years old." ) In this example, we define a class called Person . The class has two attributes: name and age . It also has a method called say_hello , which prints out a message introducing the person. The __init__ method is a special method that is called when a new object of the class is created. It sets the initial values of the name and age attributes. Import statement Import statement: Used to import modules or packages in Python. The import ...