object oriented programming(initiation)
## creating an object of a class :-instantiation.
## in other words instantiating a class
class students:
def __init__(self,name,age):##constructor definition
self.sname=name ##self refers to current object(student)
self.sage=age
print("my name is {} and my age is {}".format(self.sname,self.sage))
##self will refer to the current object
student1=students("Aamir",25)
student2=students("Noor",28)
##object name =class name()
student3=students("Danish",22)
student4=students("qruzz",23)
print(student1)
print(student2)
print(student3)
print(student4)
"C:\Users\darul Haram\PycharmProjects\pythonProject2\venv\Scripts\python.exe" "C:/Users/darul Haram/PycharmProjects/pythonProject2/venv/Lib/OOP 1(initiation).py" my name is Aamir and my age is 25 my name is Noor and my age is 28 my name is Danish and my age is 22 my name is qruzz and my age is 23 <__main__.students object at 0x0000022E1511EFD0> <__main__.students object at 0x0000022E1511EF70> <__main__.students object at 0x0000022E1511EEE0> <__main__.students object at 0x0000022E1511EE50> Process finished with exit code 0
## creating an object of a class :-instantiation.
## in other words instantiating a class
class students:
def __init__(self,name,age):##constructor definition
self.sname=name
self.sage=age
print("my name is {} and my age is {}".format(self.sname,self.sage))
##self will refer to the current object
student1=students("Aamir",25)
student2=students("Noor",28)
##object name =class name()
student3=students("Danish",22)
student4=students("qruzz",23)
print(student4.sage)##assigning the attributes
print(student2.sname)
print(student3.sage)
print(student4.sname)
"C:\Users\darul Haram\PycharmProjects\pythonProject2\venv\Scripts\python.exe" "C:/Users/darul Haram/PycharmProjects/pythonProject2/venv/Lib/OOP3( self refers to current object).py" my name is Aamir and my age is 25 my name is Noor and my age is 28 my name is Danish and my age is 22 my name is qruzz and my age is 23 23 Noor 22 qruzz Process finished with exit code 0
Comments
Post a Comment