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
最新回答 / 慕函數(shù)7083591
# Enter a code# coding=utf-8class Animal(object):? ? passdog = Animal()dog.name = '汪汪'dog.age = 7# 三種方式都可以,最后一種3.6新功能,在網(wǎng)頁上還不支持,可以本地執(zhí)行print("%s : %s" % (dog.name, dog.age))print("{} : {}".format(dog.name, dog.age))print(f"{dog.name}: {dog.age}")cat = Anima...
2024-06-11
因?yàn)槭窃陬惿险{(diào)用,而非實(shí)例上調(diào)用,因此類方法無法獲得任何實(shí)例變量,只能獲得類的引用,這句話是啥意思,上面都挺明白,這個話突然理解不了了
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