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
最新回答 / 慕函数7083591
# Enter a code# coding=utf-8class Animal(object): passdog = Animal()dog.name = '汪汪'dog.age = 7# 三种方式都可以,最后一种3.6新功能,在网页上还不支持,可以本地执行print("%s : %s" % (dog.name, dog.age))print("{} : {}".format(dog.name, dog.age))print(f"{dog.name}: {dog.age}")cat = Anima...
2024-06-11
因为是在类上调用,而非实例上调用,因此类方法无法获得任何实例变量,只能获得类的引用,这句话是啥意思,上面都挺明白,这个话突然理解不了了
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