zoukankan      html  css  js  c++  java
  • Python自动化开发之python的常用模块

    python常用模块

      模块的种类:模块分为三种,分别是自定义模块;内置标准模块(即标准库);开源模块(第三方)。

         以下主要研究标准模块即标准库:标准库直接导入即可,不需要安装。

      时间模块:time ,datetime

     例子:自定义时间格式  
    1 __author__ = 'renyongbin'
    2 import time
    3 print(time.strftime("%Y-%m-%d %H:%M:%S"))
    View Code
    
    
    运行结果:2017-03-16 15:20:04
     例子3:打印当前时间
      
    1 __author__ = 'renyongbin'
    2 import datetime
    3 print(datetime.datetime.now())
    View Code
    运行结果:2017-03-16 15:33:11.212345
      random模块:主要用来编写随机验证码。
      例子1:
      
    1 __author__ = 'renyongbin'
    2 import random
    3 #包含10
    4 print(random.randint(1,10))
    5 #不包含10
    6 print(random.randrange(1,10))
    View Code
    
    
    运行结果:

      6
      3

      例子2:在100个人中选择6个人(抽签)

    1 __author__ = 'renyongbin'
    2 import random
    3 print(random.sample(range(100),6))
    View Code

    运行结果:[86, 73, 81, 0, 59, 32] 

      例子3:随机生成验证码  

    1 __author__ = 'renyongbin'
    2 import random,string
    3 source = string.digits +string.ascii_lowercase
    4 print("".join(random.sample(source,6)))
    View Code

    运行结果:n61hlq  

  • 相关阅读:
    pandas的Categorical方法
    LightBGM之train
    LightBGM之Dataset
    pandas的replace方法
    python的tqdm模块
    pandas的merge方法
    pandas的drop函数
    各种服务器建议配置
    thymeleaf:访问静态方法
    The project cannot be built until its prerequisite base-service is built. Cleaning and building all projects is recommended
  • 原文地址:https://www.cnblogs.com/renyongbin/p/6559435.html
Copyright © 2011-2022 走看看