print("=============object, Class====================")
#Class
class newClass:
var = 10
print(newClass)
#object
newObj = newClass()
print(newObj)
print(newObj.var)
# _int_() Function
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
newStudentObj = Student("Bold", 25)
print("newStudentObj.name = ", newStudentObj.name)
print("newStudentObj.age = ", newStudentObj.age)
# object Methods
class newStudent:
def __init__(self, name, age):
self.name = name
self.age = age
def myFunc(self):
print("My name is " + self.name +
f" and i'm {self.age} years old")
newStudentObj = newStudent("Dorj", 24)
newStudentObj.myFunc()
class studentMod:
def __init__(self, name, age):
self.name = name
self.age = age
def myFunc(self):
print("My name is " + self.name +
f" and i'm {self.age} years old")
newStudentObj = newStudent("Dorj", 24)
newStudentObj.myFunc()
newStudentObj.age = 17
print("newStudentObj.age = ", newStudentObj.age)
newStudentObj.myFunc()
# del ::
del newStudentObj.age
# print("newStudentObj.age = ", newStudentObj.age)
# newStudentObj.myFunc()
"""
Traceback (most recent call last):
File "jan02Lesson.py", line 61, in <module>
print("newStudentObj.age = ", newStudentObj.age)
AttributeError: 'newStudent' object has no attribute 'age'
"""
del newStudentObj
# print(newStudentObj)
# pass::
class Human:
def __init__(self, height, weight, skinColor):
self.height = height
self.weight = weight
self.skinColor = skinColor
def humanFunc(self):
print("East Asian man average height =", self.height ,
f" and average weight = {self.weight}, skin color: {self.skinColor}")
HumanObj = Human(165, 75, "Yellow")
HumanObj.humanFunc()
height1 = int(input("Human Height ="))
weight1 = int(input("Human weight ="))
skin1 = input("Skin Color :")
HumanObj = Human(height1, weight1, skin1)
HumanObj.humanFunc()
No comments:
Post a Comment