Created
March 13, 2021 13:47
-
-
Save PANDATD/74fcac8859592dfe346f7884cc1e3731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3.8 | |
| class Person: | |
| count = 0 | |
| def __init__(self, name ,sex = 'female', age=20): | |
| Person.count = Person.count +1 | |
| self.name = name | |
| self.sex = sex | |
| self.age = age | |
| @staticmethod #Funcation Decoretor | |
| def numP(): #This is static method, beacuse it dose not self parameter | |
| print("count->",Person.count) | |
| tejas = Person('Tejas','male',19) | |
| sam = Person('sam') | |
| Vishal = Person('Vishal',age=20) | |
| Person.numP() | |
| #explenation area if you want to print the explenation remove uncomment line 35 or print stmt | |
| Explenation = ''' | |
| 1) First we created class | |
| 2) created count variable and asssing value = 0 | |
| 3) after that we created constructor | |
| 4) then we incrementing the count | |
| which means the it increments the value when | |
| we creating an instance of class which means object | |
| 5) after that we numP method [ This STATIC method beacuse it dosenot contain | |
| self method thats why we are calling its | |
| sattic method ] | |
| 6) hear we print() the count of objects created | |
| 7) we created objects like tejas sam vishal | |
| 8) after that we are calling Person.numP() method which will call numP | |
| method and executes the block | |
| ''' | |
| #print(Explenation) |
Author
PANDATD
commented
Mar 13, 2021

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment