如果一个字符串包含很多需要转义的字符,对每一个字符都进行转义会很麻烦。为了避免这种情况,我们可以在字符串前面加个前缀r,表示这是一个 raw 字符串,里面的字符就不需要转义了。
2023-04-27
# 需要注意的是,not计算的优先级是高于and和or的
# 所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
所以答案是 hello python ; hello world
# 所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
所以答案是 hello python ; hello world
2023-04-27
L = [95.5, 85, 59, 66, 72]
N = []
for item in L:
if(item > 60):
N.append(item)
N.sort(reverse=True)
print(N)
N = []
for item in L:
if(item > 60):
N.append(item)
N.sort(reverse=True)
print(N)
2023-04-24
template = 'life is short,{}'
print(template.format('you need Python'))
template = "life is {0},you need {1}"
print(template.format('short','Python'))
print(template.format('you need Python'))
template = "life is {0},you need {1}"
print(template.format('short','Python'))
2023-04-24
最新回答 / 月夜妖华
def func(L): s = 0 c = 1 if isinstance(L, list): s = sum(L) return s elif isinstance(L, tuple): for F in L: c = c * F return c else: print("Error")print(func([1, 2, 3]))print(func((1, 2,...
2023-04-22
最赞回答 / 月夜妖华
def square_of_sum(x): result = 0 y = [] for M in x: y.append(M * M) result = sum(y) return resultprint(square_of_sum([1, 2, 3, 4, 5]))print(square_of_sum([-5, 0, 5, 15, 25]))你把创建空列表放在循环外就正确了,如果循环一次就创建一个新的列表,那后面的列表会覆盖前面的列表,第一个列表最后...
2023-04-22
最赞回答 / 程序猿_郭文超
你可以这么理解,假如说你开了一家酒吧,进酒吧的人可以吃喝玩乐,但是你的酒吧为了盈利需要门票,所以每个进去的人都需要买门票,然后门口有一个人验票后才能入场。从这个例子中 你可以理解为 酒吧 就是一个方法,进去的人 吃喝玩乐指的是方法内你对于进去的人的行为的操作,而门票你可以理解为就是方法的参数也就是你指定的规则。所以定义的方法中需要有方法名,即你酒吧的名字(得让调用者能找到),然后还需要有对于参数操作即行为的定义,然后参数就是限定的规则。目前python中都是类似于弱类型,像JAVA这种在定义方法的时候回定...
2023-04-21