• Python正课79 —— 内置方法


    本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/xuexianqi/p/12673395.html

    # print(abs(-1))                 # 返回绝对值  # 1
    #
    # print(all([1, 2, 3, '']))      # 返回可迭代对象,有一个为0,None,空就是假的 # False
    # print(all([1, 2, 3, ]))        # 返回可迭代对象    # True
    #
    # print(any([]))                 # False
    #
    # print(bin(111))                # 0b1101111
    # print(oct(111))                # 0o157
    # print(hex(111))                # 0x6f
    #
    # print(bool(''))                # False
    
    # def func():
    #     pass
    
    
    # class Foo:
    #     pass
    
    
    # print(callable(Foo))            # True
    
    
    # print(chr(65))                    # A
    # print(ord('A'))                   # 65
    
    
    # # ======= 掌握 =======
    # class Foo:
    #     pass
    # obj = Foo()
    # obj.xxx = 111
    
    # print(dir(Foo))     # 可以查看可以.出来哪些属性     #['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
    
    # print(dir(obj))     # 可以查看可以.出来哪些属性     #['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'xxx']
    
    # print(divmod(1000,4))         #总数据量,每一页的数据量
    # 返回值:总页数,剩余数据       # (250, 0)
    
    # # ======= 掌握 =======
    # for i, v in enumerate(['a', 'b', 'c']):
    #     print(i, v)
    #
    # #  0 a
    # #  1 b
    # #  2 c
    
    # # ======= 掌握 =======
    # res = eval('1+2')       # eval就是执行字符串中的表达式
    # print(res)
    
    # # ======= 掌握 =======
    # 不可变集合
    # s = frozenset({1, 2, 3})
    # print(s)    # frozenset({1, 2, 3})
    
    # hash(不可变类型)
    
    # # ======= 掌握 =======
    # isinstance判断一个对象是不是一个类的实例
    # class Foo:
    #     pass
    #
    # obj = Foo()
    # print(isinstance(obj, Foo))     # True
    # print(isinstance([], list))     # True  # 推荐
    # print(type([]) is list)         # True  # 不推荐
    
    # # 10 ** 2 % 3
    # print(pow(10, 2, 3))        # 1
    
    # # 了解
    # print('aaa'.__repr__())  # 'aaa'
    
    # # round 四舍五入
    # print(round(1.545))    #  2
    # print(round(1.445))    #  1
    
    # # 切片
    # s = slice(1, 4, 2)  # 不常用
    # l1 = [1, 2, 3, 4]
    # l2 = [3, 2, 5, 9, 6, 7]
    #
    # print(l1[1:4:2])  # [2, 4]
    # print(l2[1:4:2])  # [2, 9]
    # print(l1[s])    # [2, 4]
    # print(l2[s])    #[2, 4]
    
    
    # # ======= 掌握 =======
    # # zip拉链函数 一个对一个,没有对应的就报错
    # v1 = 'hello'
    # v2 = [111, 222, 333, 444, 555]
    # res = zip(v1, v2)
    # print(list(res))    # [('h', 111), ('e', 222), ('l', 333), ('l', 444), ('o', 555)]
    
    
    # # ======= 掌握 =======
    # __import__()
    import time
    # import 'time'   # 报错
    # 变量名 = __import__('time')
    # x = __import__('time')
    # x.sleep(3)
    
    
    
    # # ======= 掌握 =======
    # 下周:反射
    
  • 相关阅读:
    模块化利器:RequireJS常用知识
    移动端适配:font-size设置的思考
    样式化复选框
    jquery tmpl 详解
    移动前端相关解决方案整理
    常用页面布局方式介绍
    移动端制作的常见问题及解决方法
    手机端页面自适应:rem布局
    React工程化之PWA之serviceWorker
    React之JSX循环遍历方法对比
  • 原文地址:https://www.cnblogs.com/xuexianqi/p/12673395.html
Copyright © 2020-2023  润新知