Learn -class package python

# + Behavior wrapper class attribute abstract = -
class StudentV2:

All instances # class properties can be shared. It does not belong to any of the examples characteristics.
is_people = True

Class Method # 1, decorators. 2, is a parameter showing cls class itself.
@classmethod
DEF pepole_aciton (CLS):
Print ( "Eat, sleep !!")
Print (cls.is_people)


# Initialization
def __init __ (self, name, stu_id, class_name, city = " Shanghai"):
self.name name = # examples of property
self.stu_id = stu_id
self.class_name = class_name
self.city = City
self._protect_friend = "chicken "
Self .__ private_money = 500
Print (" initialization is complete, I already have a specific name, student number, class, four city property. ")

# Behavior self is me, I am self. After the class is instantiated clear who I am.
attend_course DEF (Self):
# line 300 is split into four smaller function
self._private_func ()
Print ( "{} are learning classes and objects." the format (the self.name).)
return

def _private_func(self):
pass
def __private_func_deep(self):
pass


# Behavior
DEF do_homework (Self):
Print (. "{} In the homework .." the format (the self.name))
return

# Open api, get private variable value.
get_counts DEF (Self):
Print ( "I have a {} {}" format (Self .__ private_money, self._protect_friend).)
#Print (self._protect_friend)

# # Class is instantiated at the same time, we will take the initiative to call the init function.
# Luoluo = StudentV2 ( "Rolls-Royce", "222222", "python17 ", " Beijing")
# Print (luoluo.stu_id)
# luoluo.attend_course () # behavior
#
# Hukai = StudentV2 ( "Hu Kai," "333111 "," python17 "," Shenzhen ")
# Print (the above mentioned id (Hukai))
# hukai.do_homework ()

# Call the class attribute
# Print (StudentV2.is_people)
# # Print (StudentV2.name) # class is no name attribute
# StudentV2.pepole_aciton ()

luoluo = StudentV2("罗","222222","python17","北京")
# print(luoluo.is_people)
# print(luoluo.name)
# print(luoluo._protect_friend)
# print(luoluo.__private_money)
# print(luoluo._StudentV2__private_money) # 改变了方式
luoluo.get_counts()

 

"" "
Class and instance properties

The method of the class, instance method

# Private property, private behavior
_XXX private. Classes and subclasses of objects can be accessed to provide you access to the api.

__XXX private. Object class can access.
"" "

 

Guess you like

Origin www.cnblogs.com/qsmyjz/p/11261255.html