最赞回答 / 树懒先生QAQ
@是装饰符以原文为例,先定义了一个log()函数。把想要装饰函数factorial()上一行写上 @log,就完成了用log()函数里的内容去“”装饰“”factorial()函数里的内容。通过@装饰符,可以修饰某函数,使其完成自己想要的额外的功能
2021-04-22
with open('./text.txt','a+') as f1:
f1.seek(0)
lines=f1.readlines()
f1.seek(2)
for v in lines:
f1.write(v)
f1.seek(0)
lines=f1.readlines()
f1.seek(2)
for v in lines:
f1.write(v)
2021-04-15
import math
x=math.sin(0)
from math import cos
y=cos(0)
print(x,y)
x=math.sin(0)
from math import cos
y=cos(0)
print(x,y)
2021-04-14
class Student():
def __init__(self,name,gender,score):
self.name,self.gender=name,gender
self.score=score
def __str__(self):
return 'Student:{},{},{}'.format(self.name,self.gender,self.score)
s=Student('xiaowang','girl','98')
print(str(s))
def __init__(self,name,gender,score):
self.name,self.gender=name,gender
self.score=score
def __str__(self):
return 'Student:{},{},{}'.format(self.name,self.gender,self.score)
s=Student('xiaowang','girl','98')
print(str(s))
2021-04-13
print(isinstance(t,Person))
print(isinstance(t,Student))
print(isinstance(t,Teacher))
print(isinstance(t,object))
print(isinstance(t,Student))
print(isinstance(t,Teacher))
print(isinstance(t,object))
2021-04-12
最赞回答 / 小白兔cai
定义函数 def __init__(self, , ):函数是写成了 def __int__(self, , ):改写为 def __init__(self, , ):
2021-04-11
class Animal():
_count=0
@classmethod
def get_count(cls):
Animal._count+=1
return cls._count
print(Animal.get_count())
print(Animal.get_count())
_count=0
@classmethod
def get_count(cls):
Animal._count+=1
return cls._count
print(Animal.get_count())
print(Animal.get_count())
2021-04-11
class Animal(object):
def __init__(self, name, age):
self.name = name
self.age = age
dog = Animal("小黄", 2)
cat = Animal("小花", 3)
print(dog.name,dog.age)
print(cat.name,cat.age)
def __init__(self, name, age):
self.name = name
self.age = age
dog = Animal("小黄", 2)
cat = Animal("小花", 3)
print(dog.name,dog.age)
print(cat.name,cat.age)
2021-04-09
class Animal():
count=0
def __init__(self,name,age):
self.name=name
self.age=age
Animal.count+=1
dog=Animal('wangwang','2years old')
cat=Animal('mimi','1yeaes old')
print(Animal.count)
count=0
def __init__(self,name,age):
self.name=name
self.age=age
Animal.count+=1
dog=Animal('wangwang','2years old')
cat=Animal('mimi','1yeaes old')
print(Animal.count)
2021-04-09
class Animal():
def __init__(self,name,age):
self.name=name
self.age=age
dog=Animal('wangcai','3岁')
cat=Animal('mimi','2岁')
print(dog.name,dog.age)
print(cat.name,cat.age)
def __init__(self,name,age):
self.name=name
self.age=age
dog=Animal('wangcai','3岁')
cat=Animal('mimi','2岁')
print(dog.name,dog.age)
print(cat.name,cat.age)
2021-04-08
class Dog():
pass
class Cat():
pass
dog=Dog()
cat=Cat()
print(dog)
print(cat)
print(dog==cat)
pass
class Cat():
pass
dog=Dog()
cat=Cat()
print(dog)
print(cat)
print(dog==cat)
2021-04-08