• python之前期常用的内置函数


    1.常用的内置函数

    # 掌握
    # res='你好'.encode('utf-8') 编码                                                      encode  编码
    # print(res)
    #
    # res=bytes('你好',encoding='utf-8') 跟上面一样
    # print(res)


    # 参考ASCII表将数字转成对应的字符   
    # print(chr(65))                                                                                    chr      ASCLL表 数字转换字符
    # print(chr(90))
    # 参考ASCII表将字符转成对应的数字
    # print(ord('A'))                                                                                    ord      ASCLL表 字符转换数字 


    # print(divmod(10,3))   10除3  取整数和余数部分                                divmod   10除3  取整数和余数部分




    # l=['a','b','c']
    # for item in enumerate(l):
    #     print(item)


    # l='[1,2,3]'              适用于读文件内容
    # l1=eval(l)                                                                                                eval    将字符串中的表达式取出来
    # print(l1,type(l1))     将字符串中的表达式取出来 
    # print(l1[0])


    # with open('a.txt',encoding='utf-8') as f:
    #     data=f.read()
    #     print(data,type(data))
    #     dic=eval(data)
    #     print(dic['sex'])


    # print(pow(3,2,2)) # (3 ** 2) % 2  #3的2次方 除2取余                                pow    


    # print(round(3.3)) 四舍五入                                         round    四舍五入


    # print(sum(range(101)))   求和                                                              sum        求和

    c = [-10,-5,0,5,3,10,15,-20,25]

                                                                                                                                                     min  最小值

    print c.index(min(c))  # 返回最小值                                                                                    max    最大值    

    print c.index(max(c)) # 返回最大值

    print (min(80, 100, 1000))   取最小值






    module=input('请输入你要导入的模块名>>: ').strip() #module='asdfsadf'   
    m=__import__(module) 模块导入
    print(m.time())
     

    # 了解
    # print(abs(-13))        负数变正数                                                        abs
    # print(all([1,2,3,]))  判断列表所有bool值全部真返回真                        all
    # print(all([])) 返回true

            
    # print(any([0,None,'',1])) 有一个为真就就为真                                    any
    # print(any([0,None,'',0])) 空就是false
    # print(any([])) false


    # print(bin(3)) #11       十进制转换二级制                                            bin
    # print(oct(9)) #11 十进制转换八级制                                oct
    # print(hex(17)) #11 十进制转换十六级制                            hex


    # print(callable(len))    判断函数是是否可以被调用                              callable


    # import time
    # print(dir(time)) #列举出模块所有:time.名字                                    dic




    # s=frozenset({1,2,3}) # 不可变集合                                        frozenset
    # s1=set({1,2,3}) # 可变集合                                                            set


    # a=1111111111111111111111111111111111111111111111
    # # print(globals())   查看全局作用域名字                                            globals
    # # print(locals()) 查看局部作用域名字                                       locals
    # def func():
    #     x=222222222
    #     # print(globals())
    #     print(locals())
    # func()


    # hash([1,2,3])


    # def func():
    #     """
    #     文档注释
    #     :return:
    #     """
    #     pass
    #
    # print(help(func))          查看帮助                                                            help

  • 相关阅读:
    MySQL与OLAP:分析型SQL查询最佳实践探索
    创建与删除索引
    第三方推送-个推使用
    test
    图床_搭建本地yum仓库及自制rpm包(无需镜像)
    图床_有趣的linux命令行工具-lolcat
    图床_fdisk一键操作分区-无需脚本
    图床_将你的CentOS 7 配置yum源
    图床_使用Putty远程连接管理Linux实践
    图床_使用Xshell远程连接管理Linux实践
  • 原文地址:https://www.cnblogs.com/Marcki/p/10111960.html
Copyright © 2020-2023  润新知