# common.py
def say_hello(name):
print('Hello,{}'.format(name))
say_hello('LiuYF')
def say_hello(name):
print('Hello,{}'.format(name))
say_hello('LiuYF')
2025-08-14
class Fib(object):
def __init__(self):
self.res = []
def __call__(self,num):
for i in range(num):
self.res.append(i)
if i > 1:
self.res[i] = self.res[i - 1] + self.res[i - 2]
return self.res
f = Fib()
print(f(10))
def __init__(self):
self.res = []
def __call__(self,num):
for i in range(num):
self.res.append(i)
if i > 1:
self.res[i] = self.res[i - 1] + self.res[i - 2]
return self.res
f = Fib()
print(f(10))
2025-08-13
class Student(object):
def __init__(self,name,ge):
self.name = name
self.ge = ge
def __str__(self):
return 'Student: {},{}'.format(self.name,self.ge)
def __repr__(self):
return 'Student:{},{}'.format(self.name,self.ge)
s = Student('憶雪','女',88)
print(s)
def __init__(self,name,ge):
self.name = name
self.ge = ge
def __str__(self):
return 'Student: {},{}'.format(self.name,self.ge)
def __repr__(self):
return 'Student:{},{}'.format(self.name,self.ge)
s = Student('憶雪','女',88)
print(s)
2025-08-13
# -*- coding: utf-8 -*-
class Person(object):
def __init__(self,name,gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self,name,gender,su):
super(Teacher,self).__init__(name,gender)
self.su= su
teacher = Teacher('弘','男','歷')
class Person(object):
def __init__(self,name,gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self,name,gender,su):
super(Teacher,self).__init__(name,gender)
self.su= su
teacher = Teacher('弘','男','歷')
2025-08-13
class Animal(object):
def __init__(self,name,age,location):
self.__name = name
self.__age = age
self.__location = location
def g(self):
return 'n = {}, a = {}, l = {}'.format(self.__name,self.__age,self.__location)
dog = Animal('T',5,'A')
print(dog.g())
def __init__(self,name,age,location):
self.__name = name
self.__age = age
self.__location = location
def g(self):
return 'n = {}, a = {}, l = {}'.format(self.__name,self.__age,self.__location)
dog = Animal('T',5,'A')
print(dog.g())
2025-08-12
class Animal(object):
_count = 0
def __init__(self,name,age):
self.name = name
self.age = age
Animal._count += 1
dog = Animal('kg',12)
print(dog._count)
print(Animal._count)
_count = 0
def __init__(self,name,age):
self.name = name
self.age = age
Animal._count += 1
dog = Animal('kg',12)
print(dog._count)
print(Animal._count)
2025-08-12
class Animal(object):
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('Tom',3)
cat = Animal('Lily',2)
print(dog.name)
print(dog.age)
print(cat.name)
print(cat.age)
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('Tom',3)
cat = Animal('Lily',2)
print(dog.name)
print(dog.age)
print(cat.name)
print(cat.age)
2025-08-12
class Animal(object):
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
2025-03-08
最新回答 / tinghai
執(zhí)行報錯:Traceback (most recent call last):? File "E:\python\example\lizi.py", line 283, in <module>? ? student = Student('Alice',100)? ? ? ? ? ? ? ^^^^^^^^^^^^^^^^^^^^? File "E:\python\example\lizi.py", line 280, in __init__? ? super(Student, self).__i...
2025-02-07
super詳解:https://www.runoob.com/w3cnote/python-super-detail-intro.html
2025-02-01