• Day 4-2 random模块


    1 import random
    2 random.randint(1,100)  # 从1到100中随机取出一个数.包含100
    3 random.randrange(1,100) #功能和上面一样.只是不包含100.
    4 random.random()         # 取一个随机浮点数.
    5 random.choice("123kldsjfoiauofjdlkcvjhasfhsafjr")  # 从字符串中随机返回一个字符
    6 random.sample("vajoure034zmvm2i0989383242u",4)  # 返回指定数量的字符串

    生成一个随机验证码:

    1 # 生成一个随机验证码,需要string模块
    2 import string
    3 string.ascii_letters  # 大小写字母
    4 string.digits        # 数字.
    5 string.punctuation   # 特殊字符
    6 s = string.ascii_letters + string.digits
    7 s1 = ''.join(random.sample(s,4))   # 生成一个4位的随机验证码.
    8 print(s1)

       打乱顺序:

    1 # 打乱顺序
    2 li = list(range(100))  # 生成一个列表
    3 random.shuffle(li)    #打乱列表中的顺序
    4 print(li)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • 相关阅读:
    IfcSameDirection
    IfcSameCartesianPoint
    java多个文件合并为一个文件
    matlab pan_tompkin算法
    IfcSameAxis2Placement
    IfcOrthogonalComplement
    IfcNormalise
    IfcMakeArrayOfArray
    matlab 日期 年月日时分秒毫秒
    IfcListToArray
  • 原文地址:https://www.cnblogs.com/lovepy3/p/8748530.html
Copyright © 2020-2023  润新知