[Python3] I made my first class! Feedback please.



Well, I just started a course on OOP with Python. Up until this point I had a lot of trouble grasping the concepts of, attributes and objects relating to classes but, I think I got it.  


Can any Python experts comment below and let me know what you think about my first useful class with methods.


# This is a test class made on 7/6/2017.
# Creates a class called User and sets, attributes for name and birth.
# Calculated how old user is and if their "oldenough" < 25 returns False.
# Alot of this is to just test things out
class User:
 #Birthday in yyyymmdd format
 def __init__(self, name, birth):
     self.name = name
     self.birth = birth
     self.byear = birth[0:4]
 #Checks year current year minus year born returns year born
 def yearsold(self):
     year = 2017
     age = year - int(self.byear)
     return age
 #returns False if younger than 25, and True for older than 25   
 def oldenough(self):
     if self.yearsold() < 25:
         return False
     else:
         return True
#Assigning an object called Ted to User with the required attributes
ted = User("Ted", "19941013")
rick = User("Rick", "18011230")
print(ted.name)
print(ted.byear)
print(ted.yearsold())
print(ted.oldenough())
print('.' * 25)
print(rick.name)
print(rick.byear)
print(rick.yearsold())
print(rick.oldenough())
#checks if the user is old enough 
#just wanted to test things out
if ted.oldenough() != True:
 print("Sorry {} you're only {} years old!".format(ted.name,ted.yearsold()))
else:
 print("Access Granted to: {}".format(ted.name))


H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center