1 Python中内置数据类型list,tuple,dict,set的区别和用法?
https://www.jb51.net/article/76339.htm
2 Python中装饰器是什么,内置的哪些装饰器?
https://www.cnblogs.com/XhyTechnologyShare/p/11997361.html
3 Python 类中的 init、new、call 方法
https://www.cnblogs.com/bingpan/p/8270487.html
4输出下面值?
class Parent(object):
x = 1
class Child1(Parent):
pass
class Child2(Parent):
pass
print(Parent.x, Child1.x, Child2.x)
Child1.x = 2
print(Parent.x, Child1.x, Child2.x)
Parent.x = 3
print(Parent.x, Child1.x, Child2.x)
1 1 1
1 2 1
3 2 3
5写出去掉重复元素的列表代码实现?
list1 = [2, 5, 4, 4, 5, 6]
new_list = list(set(list1))
print(new_list)
6写出0-100的偶数
list = [x for x in range(100) if x%2 ==0]
print(list)
7请把[[1,2,3],[4,5,6],[7,8,9]]
转成[1, 2, 3, 4, 5, 6, 7, 8, 9]
arr = [[1,2,3],[4,5,6],[7,8,9]]
new_list = []
for list in arr:
for l in list:
new_list.append(l)
print(new_list)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
8 列表里的字典进行排序
lst = [{"a": 3}, {"b": 1}, {"c": 5}]
def foo(x):
for key, value in x.items():
return value
sort_dict = sorted(lst, key=foo, reverse=False)
print(sort_dict)