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
class Pen(object):
count = 0
def __init__(self, name, len):
self.name = name
self.len = len
Pen.count += 1
red_pen = Pen('红笔', 5)
black_pen = Pen('黑笔', 6)
print(Pen.count)
count = 0
def __init__(self, name, len):
self.name = name
self.len = len
Pen.count += 1
red_pen = Pen('红笔', 5)
black_pen = Pen('黑笔', 6)
print(Pen.count)
2024-04-29
class animal(object):
def __init__(self, name, color):
self.name = name
self.color = color
dog = animal('阿黄', '金色')
cat = animal('阿欢', '灰色')
print(dog.name)
def __init__(self, name, color):
self.name = name
self.color = color
dog = animal('阿黄', '金色')
cat = animal('阿欢', '灰色')
print(dog.name)
2024-04-28
def f(x):
return pow(x, 0.5)
for item in map(f, range(1, 101)):
if item == int(item):
print(int(item))
def z(item):
if item == int(item):
return print(int(item))
for item in filter(z, [item]):
print(item)
return pow(x, 0.5)
for item in map(f, range(1, 101)):
if item == int(item):
print(int(item))
def z(item):
if item == int(item):
return print(int(item))
for item in filter(z, [item]):
print(item)
2024-04-23
from functools import reduce
def f(x, y):
return x * y
print(int(reduce(f, [1.0, 3.0, 5.0, 7.0, 9.0])))
def f(x, y):
return x * y
print(int(reduce(f, [1.0, 3.0, 5.0, 7.0, 9.0])))
2024-04-22
import math
def add(a, b, f):
return f(a) + f(b)
print(int(add(1, 4, math.sqrt)))
def add(a, b, f):
return f(a) + f(b)
print(int(add(1, 4, math.sqrt)))
2024-04-22
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
print(count())
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
print(count())
2024-04-03
两层不就够了
from functools import reduce
def cale_prod(list1):
def ji(x,y):
return x*y
return reduce(ji,list1)
list1 = list(map(int, input().split(',')))
print(cale_prod(list1))
from functools import reduce
def cale_prod(list1):
def ji(x,y):
return x*y
return reduce(ji,list1)
list1 = list(map(int, input().split(',')))
print(cale_prod(list1))
2024-04-03
f = open('6.txt', 'a+')
f.seek(0)
content = f.readlines()
f.seek(2)
f.writelines('\n')
f.writelines(content)
f.close()
这样比较合理
f.seek(0)
content = f.readlines()
f.seek(2)
f.writelines('\n')
f.writelines(content)
f.close()
这样比较合理
2024-03-29