zoukankan      html  css  js  c++  java
  • Python中逗号作用的实例分析

    逗号在类型转化中的使用 主要是元组的转换

    例如:

    >>> a=11
    >>> b=(a)
    >>> b
    11
    >>> b=(a,)
    >>> b
    (11,)
    >>> b=(a,22)
    >>> b
    (11, 22)
    >>> b=(a,22,)
    >>> b
    (11, 22)
    >>>

    从中可以看出  只有当b元组中只有一个元素的时候  需要逗号来转换为元组类型

    另外,这个多线程里的逗号很有意思,一旦去掉,程序就会报错

    #coding=utf-8
    import threading
    from time import ctime,sleep


    def music(func):
        for i in range(2):
            print("I was listening to %s. %s" %(func,ctime()))
            sleep(1)

    def move(func):
        for i in range(2):
            print("I was at the %s! %s" %(func,ctime()))
            sleep(5)

    threads = []
    t1 = threading.Thread(target=music,args=(u'爱情买卖',))
    threads.append(t1)
    t2 = threading.Thread(target=move,args=(u'阿凡达',))
    threads.append(t2)

    if __name__ == '__main__':
        for t in threads:
            t.setDaemon(True)
            t.start()
        t.join()
        print("all over %s" %ctime())

  • 相关阅读:
    mysql注入小测试
    让函数返回指定值实用写法
    源码下载网址
    带宽
    九度oj 题目1080:进制转换
    九度oj 题目1079:手机键盘
    poj 3046 Ant Counting
    整数拆分问题
    poj 2229 Sumsets
    九度oj 题目1411:转圈
  • 原文地址:https://www.cnblogs.com/shengulong/p/5191584.html
Copyright © 2011-2022 走看看