zoukankan      html  css  js  c++  java
  • 16.python内置函数

    Python 内置函数:https://www.runoob.com/python/python-built-in-functions.html

    原文:https://www.cnblogs.com/linhaifeng/articles/6113086.html#_label12

    # 绝对值
    # print(abs(-1))
    # print(abs(1))
    #
    # 有一个为假就false,如果为空就是true
    # Return True if bool(x) is True for all values x in the iterable.
    # If the iterable is empty, return True.
    # print(all([1,2,'1']))#True
    # print(all([1,2,'1','']))#False
    # print(all('1230'))#True
    # print(all(''))#True
    
    # 有一个是真,就是true
    # print(any([0,'']))
    # print(any([0,'',1]))
    
    # 转2进制
    # print(bin(3))
    
    #空,None,0的布尔值为False,其余都为True
    # print(bool(''))
    # print(bool(None))
    # print(bool(0))
    
    # 加码解码
    # name='你好'
    # print(bytes(name,encoding='utf-8'))
    # print(bytes(name,encoding='utf-8').decode('utf-8'))
    #
    # print(bytes(name,encoding='gbk'))
    # print(bytes(name,encoding='gbk').decode('gbk'))
    #
    # print(bytes(name,encoding='ascii'))#ascii不能编码中文
    
    # chr() 用一个范围在 range(256)内的(就是0~255)整数作参数,返回一个对应的字符。
    # print(chr(46))
    
    # dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;
    # 带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。
    # 如果参数不包含__dir__(),该方法将最大限度地收集参数信息。
    # print(dir(dict))
    
    # python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。
    # print(divmod(10,3))
    
    # dic={'name':'alex'}
    # dic_str=str(dic)
    # print(dic_str)
    
    #可hash的数据类型即不可变数据类型,不可hash的数据类型即可变数据类型
    # print(hash('12sdfdsaf3123123sdfasdfasdfasdfasdfasdfasdfasdfasfasfdasdf'))
    # print(hash('12sdfdsaf31231asdfasdfsadfsadfasdfasdf23'))
    #
    # name='raito'
    # print(hash(name))
    # print(hash(name))
    #
    #
    # print('--->before',hash(name))
    # name='sb'
    # print('=-=>after',hash(name))
    
    # help() 函数用于查看函数或模块用途的详细说明。
    # print(help(all))Python 内置函数
    
    # print(bin(10))#10进制->2进制
    # print(hex(12))#10进制->16进制
    # print(oct(12))#10进制->8进制
    
    
    # isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
    #
    # isinstance() 与 type() 区别:
    #
    # type() 不会认为子类是一种父类类型,不考虑继承关系。
    #
    # isinstance() 会认为子类是一种父类类型,考虑继承关系。
    #
    # 如果要判断两个类型是否相同推荐使用 isinstance()。
    
    # print(isinstance(1,int))
    # print(isinstance('abc',str))
    # print(isinstance([],list))
    # print(isinstance({},dict))
    # print(isinstance({1,2},set))
    
    # name='奋斗奋斗奋斗东方的'
    # print(globals())
    # print(__file__)
    #
    # def test():
    #     age='1111111111111111111111111111111111111111111111111111111111111'
    #     # print(globals())
    #     print(locals())
    #
    # test()
    
    # l=[1,3,100,-1,2]
    # print(max(l))
    # print(min(l))
  • 相关阅读:
    html websocket
    使用公钥进行远程登录主机/远程执行命令
    cropper.js 跨域问题
    利用PhantomJS生成网站截图
    Windows下的MySQL删除data文件夹后……
    快速设置环境变量
    压缩JS时生成source_map
    调试android chrome web page简明备忘
    CURL 简介【转载】
    一些同形异码字符
  • 原文地址:https://www.cnblogs.com/raitorei/p/11813694.html
Copyright © 2011-2022 走看看