python问题总结(发现新问题会补充)

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 类中的 initnewcall 方法
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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值