zoukankan      html  css  js  c++  java
  • python开发技术详解(五)

    文章目录:

      sys.modules

      python程序结构

      python内置函数

      字符串

      时间字符串转换


    sys.modules

    sys.modules 全局变量,其实就是一个字典

    zip 

    a=(1,3,4,5,6)
    b=(3,4,5,6)
    c=(1,3,4,5,1)
    print zip(a,b,c)

    output:

    [(1, 3, 1), (3, 4, 3), (4, 5, 4), (5, 6, 5)]

    set

    a=(1,3,4,5,6)
    b=(3,4,5,6,7)
    
    print set(a)|set(b)
    print set(a)-set(b)
    print set(a)&set(b)

    output:

    set([1, 3, 4, 5, 6, 7])
    set([1])
    set([3, 4, 5, 6])


    python内置函数:

     apply #将函数和参数分离开来。  

    def sum(x,y):
        return x+y
    
    print apply(sum,(1,3)) 

     map

    print map(lambda x:x**2,(1,3,4,5))

    fliter 根据函数过滤多余的元素

    def judge(x):
        if x>1:
            return True
            
    
    print filter(judge, (1,3,4,6,7))

    reduce  循环运算:

    def sum(x,y):
        return x+y
    
    print reduce(sum,(1,3,4))   #reduce一定要有两个参数。

    字符串

      %s 字符串

      %f 浮点数

      %c 字符

      %d 数字


    时间字符串转换:

    import time
    
    t=time.localtime(time.time())
    
    time.strftime('%Y-%m-%d %H-%M-%S',t); #时间戳转换为字符串
    
    t=time.strptime('2008-08-09', '%Y-%m-%d') #字符串转化为时间
    
    print time.mktime(t)    #structTime转换为时间戳

  • 相关阅读:
    WEB
    Java
    数据库
    node笔记(持续更新)
    mysql数据库关于表的操作
    flutter 文本 更多 收起
    flutter 处理时间字符串
    flutter 轮播图动态加载网络图片
    写flutter项目之一脚一个坑,持续踩坑中
    flutter json数据解析
  • 原文地址:https://www.cnblogs.com/canbefree/p/4024430.html
Copyright © 2011-2022 走看看