Python classes and objects

The class is a structural material structure. Things have a lot of variables and have a tradition of them. Python class is created in the core class. An object is created using the classroom constructor. These are then described in the class sample.

                                                 

Python classes/shapes:

Python is the product of the product. Nearly everything in Python is a thing, with its characteristics and methods. A class is like a constructor, or "ready" to create objects.

Create a class:

To create a classroom, use the key class

For example:

Create a class called MyClass, which has properties called x:

    class MyClass:

    x = 5

Create Object:

Now we can use myClass's name in the class to create elements

For example:

Create a name called P1, print value x:

     p1 = MyClass()

     print(p1.x)

__Init __ () Function:

Examples of the early grades are the easiest method, not effective in real life applications.
Understanding the meaning of the class is to understand () the activities are included __init __.
All classes have a task named __init __ (), which always comes when the class starts.
Using __ __init () to set the value of the item object, or other activities that need to be done when the product is created

For example:

Create a class called a person, with __init __ () to set the value of the name and age:
methods of the product

 class Person:

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

 p1 = Person("John"36)

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

Object Methods:

Other items may include methods. Procedures for items in the product.
Let's do this in the classroom

For example:

work by pressing the finger scroll and the P1 product:


class Person:

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

 p1 = Person("John"36)

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

The self Parameter:

Self-reliance is a reference for a unique class and is used to make changes in the classroom.
You should not be called, you can call what you like, but it is the first of all the classroom work

For example:

class Person:

  def __init__(mysillyobject, name, age):
    mysillyobject.name = name
    mysillyobject.age = age
def myfunc(abc):
    print("Hello my name is " + abc.name)
p1 = Person("John"36)
p1.myfunc()

Modify Object Properties:

Use the word Mysillyobject ABC instead of you:
Description of properties of substances
You can change the properties of the following

For example:

P1 at 40
p1.age = 40

Attributes of deleted items:


You can remove the properties of the substance by using the keyword

For example:

Remove the age of the item P1:
del p1.age

Deleted items:

You can delete an item by using the keyword

For example:

Remove the item from P1:


Comments

Popular posts from this blog

Python – Functions

What is Django in python?

Python Shallow Copy and Deep Copy