class Animal(object):
__count= 999
def __init__(self, name):
self.name = name
@classmethod
def set_count (cls, new_count):
cls.__count=new_count
@classmethod
def get_count(cls):
return cls.__count
print(Animal.get_count())
Animal.set_count(9868)
print(Animal.get_count())
__count= 999
def __init__(self, name):
self.name = name
@classmethod
def set_count (cls, new_count):
cls.__count=new_count
@classmethod
def get_count(cls):
return cls.__count
print(Animal.get_count())
Animal.set_count(9868)
print(Animal.get_count())
2024-10-21
class Animal(object):
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog: Animal = Animal('dog',3)
cat = Animal('cat',5)
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog: Animal = Animal('dog',3)
cat = Animal('cat',5)
2024-09-19
寫的一言難盡。。。。推薦大家耐心看這個算了廖雪峰python學習:https://liaoxuefeng.com/books/python/introduction/index.html
2024-09-13
L = ['alice', 'BOB', 'CanDY']
def trans(theStr):
return str(theStr).title()
for item in map(trans,L):
print(item)
def trans(theStr):
return str(theStr).title()
for item in map(trans,L):
print(item)
2024-07-09
class person(object): pass xiaohong = person() xiaoming = person()
2024-06-17
因為是在類上調用,而非實例上調用,因此類方法無法獲得任何實例變量,只能獲得類的引用,這句話是啥意思,上面都挺明白,這個話突然理解不了了
2024-05-24
p = ['bob', 'about', 'Zoo', 'Credit']
print(sorted(p, key=str.lower))
print(sorted(p, key=str.lower))
2024-05-04
class student(object)def __init__(self, name, gender, score)self.name = nameself.gender = genderself.score = scoredef __str__(self):return 'name: {}, gender: {}, score: {}'.format(self.name, self.gender, self.score def __repr__(self): return 'name: {}, gender: {}'.format(s太多了打不上去
2024-05-03
class pen(object):
def __init__(self, len):
self.len = len
def get_infro(self):
return 'len: {}'.format(self.len)
blackpen = pen(19)
a = blackpen.get_infro
print(a)
def __init__(self, len):
self.len = len
def get_infro(self):
return 'len: {}'.format(self.len)
blackpen = pen(19)
a = blackpen.get_infro
print(a)
2024-05-01