Popular Posts

Monday, September 14, 2020

Python Beginner: Object Functions

 Hello, Developer! 😄


Today, we will learn "Object Functions". Object Functions enable you to call the functions in the object and modify the values in the function in the object.


I showed full exercise codes and executed result as follow.

Student2

class Student2:
def __init__(self, name, major, gpa):
self.name = name
self.major = major
self.gpa = gpa

def on_honor_roll(self):
if self.gpa >= 3.5:
return True
else:
return False

Object Functions

from Student2 import Student2

student1 = Student2("Oscar", "Accounting", 3.1)
student2 = Student2("Phyllis", "Business", 3.8)

print(student1.on_honor_roll())
print(student2.on_honor_roll())

Execution Result

Can you see the same result on your PC? Congratulations! Now you can handle the function in the object.


Thank you for reading! See you again at the next post! 😊

No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...