美文网首页
【基础】练习册51-Python3_单线程:按顺序执行任务

【基础】练习册51-Python3_单线程:按顺序执行任务

作者: Alyna_C | 来源:发表于2021-02-17 08:30 被阅读0次

    单线程:按顺序执行任务

    代码如下:

    #coding=utf-8

    #单线程:按顺序执行任务

    from time import sleep,ctime

    #创建音乐任务

    def music(func):

        for i in range(2):

            print('I was listening to %s! %s'%(func,ctime()))

            sleep(2)

    #创建看电影任务

    def movie(func):

        for i in range(2): 

            print('I was at the %s! %s'%(func,ctime()))

            sleep(3)

    if __name__ == "__main__":

        music("Just one last dance")

        movie(u"都挺好")

    print("All end:",ctime())

    运行结果为:

    I was listening to Just one last dance! Mon Feb 1 22:22:18 2021

    I was listening to Just one last dance! Mon Feb  1 22:22:20 2021

    I was at the 都挺好! Mon Feb  1 22:22:22 2021

    I was at the 都挺好! Mon Feb  1 22:22:25 2021

    All end: Mon Feb  1 22:22:28 2021

    相关文章

      网友评论

          本文标题:【基础】练习册51-Python3_单线程:按顺序执行任务

          本文链接:https://www.haomeiwen.com/subject/ihzstltx.html