Using class objects, Instance variables, and class variables, class methods and static method in python
Using class objects, Instance variables, and class variables, class methods and static method in python
Code -
------------------------------------
class Students:
number_of_buildings = 4
# def Majra(self):
# return f"Number of toys are {self.toys}, and number of buildings are {self.number_of_buildings}"
def __init__(self, name, aclass, section, rollnumber, school, stream):
self.name = name
self.standard = aclass
self.section = section
self.Roll_number = rollnumber
self.School = school
self.stream = stream
def eye_checker(self):
return f"Class is {self.standard}, and name is {self.name}"
@classmethod
def hello(cls, no_of_new_buildings):
cls.number_of_buildings = no_of_new_buildings
@classmethod
def object_creator(cls, string):
# b = string.split("-")
# cls(b[0], b[1], b[2], b[3], b[4], b[5]
return cls(*string.split("-"))
@staticmethod
def heroic(x, y):
return x + y
anant = Students("Anant", 11, "G", 6, "B.B.S.S.M I/C", "Commerce")
utsav = Students("Utsav", 11, "A", 40, "B.B.S.S.M I/C", "PCM")
# a = input("String enter here with seperating each field with '-' \n")
# hariom = Students.object_creator(a)
# print(anant.__dict__, "\n", utsav.__dict__)
#
# print(anant.eye_checker(), "\n", utsav.eye_checker())
#
# anant.hello(40)
#
# print(anant.number_of_buildings)
#
# print(utsav.number_of_buildings)
#
# print(Students.number_of_buildings)
#
# print(hariom.__dict__)
# print(Students.heroic("hello", " world"))
Comments
Post a Comment