---恢复内容开始---
16.请问这个函数有多少个参数?
def MyFun((x,y), (a, b)):
return x * y - a * b
无参数 语法定义错误
17.编写一个函数满足以下功能:
计算打印所有参数的和乘以基数(base=3)的结果
def text4(*number , base= 3): s = 0 for i in number: s = i + s s = s * base print(s) text4(1,2,3,5)
1.
下面代码会输出什么
def
f(x,l
=
[]):
for
i
in
range
(x):
l.append(i
*
i)
print
l
f(
2
)
f(
3
,[
3
,
2
,
1
])
f(
3
)
[0, 1] [3, 2, 1, 0, 1, 4] [0, 1, 0, 1, 4]
2.列表的sort方法和sorted的区别是什么?试举例说明?
l1 = ['b','c','d','b','c','a','a'] l1.sort() print(l1) l3 =sorted(l1) print(l3)
3.尝试用两个方式,分别用一行语句实现去除了中的相同项,将结果存放在l2列表中
l1 = ['b','c','d','b','c','a','a']
l2 = []
l1 = ['b','c','d','b','c','a','a']
l2 = []
l2 = list(set(l1))
print(l2)
[l2.append(i) for i in l1 if i not in l2]
print(l2)
5.现有一个由100以内所有偶数组成的列表,将列表中所有能被4和6整除的数去除
l =[] for i in range(101): if i % 2 == 0 : l.append(i) else: continue for i in l: if i % 4 == 0 or i % 6 ==0: l.remove(i) else: continue print(l)
---恢复内容结束---