#declaring and instantiating class is straight forward
# Example file for working with classes
class myClass():
def method1(self):
print("LM")
def method2(self, someString):
print("Software Testing:" + someString)
def main():
# exercise the class methods
c = myClass()
c.method1()
c.method2(" Testing is fun")
if __name__ == "__main__":
main()
#below is how inheriting a class
# Example file for working with classes
class myClass():
def method1(self):
print("LM")
class childClass(myClass):
# def method1(self):
# myClass.method1(self);
# print ("childClass Method1")
def method2(self):
print("childClass method2")
def main():
# exercise the class methods
c2 = childClass()
c2.method1()
# c2.method2()
if __name__ == "__main__":
main()
#Here is how to make use of python class constructors
class User:
name = ""
def __init__(self, name):
self.name = name
def sayHello(self):
print("Welcome to Learning, " + self.name)
User1 = User("LM User")
User1.sayHello()
# Example file for working with classes
class myClass():
def method1(self):
print("LM")
def method2(self, someString):
print("Software Testing:" + someString)
def main():
# exercise the class methods
c = myClass()
c.method1()
c.method2(" Testing is fun")
if __name__ == "__main__":
main()
#below is how inheriting a class
# Example file for working with classes
class myClass():
def method1(self):
print("LM")
class childClass(myClass):
# def method1(self):
# myClass.method1(self);
# print ("childClass Method1")
def method2(self):
print("childClass method2")
def main():
# exercise the class methods
c2 = childClass()
c2.method1()
# c2.method2()
if __name__ == "__main__":
main()
#Here is how to make use of python class constructors
class User:
name = ""
def __init__(self, name):
self.name = name
def sayHello(self):
print("Welcome to Learning, " + self.name)
User1 = User("LM User")
User1.sayHello()
references:
https://www.guru99.com/python-tutorials.html
No comments:
Post a Comment