• python 内置函数



    chr 数字转换字母

    r = chr(65)
    print(r)

    ord字母转换数字
    n = ord("A")
    print(n)


    random 函数

    import random

    li = []
    for i in range(6):
    temp = random.randrange(65, 91)
    c = chr(temp)

    li.append(c)
    result = " ".join(li)
    print(result)

    生成随机验证码
    import random

    li = []
    for i in range(6):
    r = random.randrange(0, 5) 不固定2-4 之间
    if r == 2 or r == 4: 2-4 之间生成数字
    num = random.randrange(0 ,10) 数字
    li.append(str(num))
    else:
    temp = random.randrange(65,91) 字母
    c = chr(temp)
    li.append(c)

    result = " ".join(li)
    print(result)

    compile
    compile() 将字符串 编译成python代码

    exec

    exec("7+9+8") 执行python 代码接收 代码或字符串 没有返回值


    eval

    ret = eval("7+9+8") 执行表达式 有返回结果
    print(ret)

    dir 快速查看 对象提供了哪些类
    print(dir(list))

    help(list)

    divmod 计算余数


    共97 每页显示10条 需要多少页

    '''r = divmod(100,10)
    print(r[0]) 余数
    print(r[1]) 除后的值

    b,r = divmod(100,10)
    print(b)
    print(r)


    isinstance用于判断 对象是否是某个类的实例
    s = [ 11,22,33]
    r = isinstance(s,list)
    print(r) 为真返回True

    求大于22的数字
    def f1(args):
    result = []
    for item in args:
    if item > 22:
    result.append(item)
    return result

    li = [11,22,33,44,55]
    ret = f1(li)
    print(ret)

    filter (函数 可迭代的对象)

    def f2(a):
    if a > 22:
    return True
    li = [11,22,33,44,55]

    ret = filter(f2, li)
    print(list(ret))

    map
    li = [11,22,33,44,55]

    def f2(a):
    return a + 100

    result = map(f2,li)
    print(list(result))'''

    result = map(lambda a: a + 200, li)
    print(list(result))

    filter 函数返回True 将元素添加到结果中
    map 将函数返回值添加到结果中

    hash哈希
    '''s = "李杰"
    print(hash(s))''' #哈希

    s = "李杰"
    print(len(s))
    b = bytes(s,encoding = 'utf-8')
    print(len(b))

    zip

    def show():
    a = 123
    c = 123
    print(locals())
    print(globals())

    show()

    l1 = ["alex",11,22,33]
    l2 = ["is",11,22,33]
    l3 = ["sb",11,22,33]

    r = zip(l1,l2,l3)
    temp = list(r)[0]
    ret = ' '.join(temp)
    print(ret)

    round 四舍五入
    a = 4.5
    print(round(a))

    max,min,sun 最大值 最小值求和
    a = 11,22,55
    print(max(a))
    print(min(a))
    print(sum(a))

  • 相关阅读:
    php 下载保存文件保存到本地的两种实现方法
    MySQL select语句直接导出数据
    Go学习笔记03-附录
    Go学习笔记02-源码
    Go学习笔记01-语言
    Go语言极速入门手册
    最简单的抓取网络图片或音乐文件
    使用PHP生成PDF文档
    Oracle常用函数
    ORACLE常用数值函数、转换函数、字符串函数
  • 原文地址:https://www.cnblogs.com/hanwei999/p/6082416.html
Copyright © 2020-2023  润新知