Skip to content

Instantly share code, notes, and snippets.

@PANDATD
Created March 13, 2021 13:47
Show Gist options
  • Select an option

  • Save PANDATD/74fcac8859592dfe346f7884cc1e3731 to your computer and use it in GitHub Desktop.

Select an option

Save PANDATD/74fcac8859592dfe346f7884cc1e3731 to your computer and use it in GitHub Desktop.
#!/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)
@PANDATD
Copy link
Author

PANDATD commented Mar 13, 2021

output_of_static_method py

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