1. 程式人生 > >面向對象的類

面向對象的類

fomat lan var call abc dna bject () declare

class Student:   # declare the class
__abc=1111111
def __init__(self,name,age,sex,grade,landname,pwd):
self.name=name
self.age=age
self.sex=sex
self.grade=grade
self.landname=landname
self.__pwd=pwd #creat private variable
def behavior(self):
print("Hi,how are you?")
def print_Student_info(self):
print("\nThe infomation of "+self.name+" is:",self.name,self.age,self.sex,self.grade)
def print_count_info(self):
print("\nLand_name:"+self.name+"\nPassword:"+self.__pwd )
def dispPwd(self):
return self.__abc
#h=Sayhi() #creat object
#h.Sayhello() #calling mathod of the class

#input student variable argument info(name age sex grade landname pwd)
# a=322
# b=222
Tom=Student
Tom=Student("Tom","12","F","98","tom","854xxx")
Tom.name
Tom.behavior()
Tom.print_Student_info()
Tom.print_count_info()

#print Tom._pwd
#print Tom.dispPwd()

面向對象的類