Pythonモジュール01/カスタムモジュール/timeモジュール/datetimeモジュール/randomモジュール

6784 ワード

Pythonモジュール01/カスタムモジュール/timeモジュール/datetimeモジュール/randomモジュール
コンテンツアウトライン
1.カスタムモジュール
2.timeモジュール
3.datetimeモジュール
4.randomモジュール
1.カスタムモジュール
1.モジュールをカスタマイズ
# 1.        
    # import #    (    )

    :
#     1.    (   ) -- python      .py  (  )
#     2.     (      ) --         (        ) (pypi)
#     3.     (    ) --        

  :
          :
#       1.       
#       2.      
#       3.    

# import test
# test.func()

2.起こったことを導入する
# 2.1                 (test)
# 2.2            
# 2.3      .      (  )

# print(locals())
# import test
# print(locals())

# import test
# print(test.name)
# print(test.func())

#     :
# import test.py
# print(test.py.func())
# import test


# import test
# import test
# import test
# import test
# import test
# print(test.name)

# import test as t
# print(t.name)
                    

       :
# 1.            
# msg = """
# 1.  
# 2.   
# >>>
# """
#      
# choose = input(msg)
# if choose == "1":
#     import meet
#     meet.func()
# elif choose == "2":
#     import test
#     test.func()

# #      
# choose = input(msg)
# if choose == "1":
#     import meet as t
# elif choose == "2":
#     import test as t
#
# t.func()


# import test  #        

# from test import func
# func()

import   from    
import #        
       :       
       :                    

        # import test
        # name = "  "
        # print(test.name)
        # print(name)

from :
      :                   

        # name = "  "
        # from test import name
        # print(name)

            :
            # name = "  "
            # from test import name as n
            # print(name)
            # print(n)

      :       

# name = "  "
# def func():
#     print("is      ")

# from test import *
# print(name)
# func()

# from test import *         ,    
#         

# from meet import *
# print(func)
# print(name)
#
# __all__ = ["             "]

# from meet import foo
# import meet
# print(meet.foo)

# __all__ = ["             "]

#        
# name = "  "
# import test
# print(test.name)

       :
#   1.  ( cmd    python test.py)
#   2.  (       )

# from meet import *
# func()

# __name__ == meet

# from test import *
# if __name__ == '__main__': #     
#     func()

        __name__    "__main__"
         __name__         

    :
# import meet
# print(meet.name)

      :
# from day15.t1 import meet
# print(meet.name)

      :
#     :
    # from r"D:\" import meet
    # from ../

       :
# from sys import path
# path.insert(0,"D:\\")
# import meet
# print(meet.name)
     >    >    

2.timeモジュール
# time --   

# import time
# print(time.time())  #        
# print(time.time() + 5000000000)  #        
# time.sleep(3) #             #  

# print(time.strftime("%Y-%m-%d %H:%M:%S"))  #     

# print(time.gmtime())  #                 
# print(time.gmtime()[0])
# print(time.gmtime().tm_year)


#             
# print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime(1564028611.631374)))

#             
# print(time.mktime(time.strptime("2024-3-16 12:30:30","%Y-%m-%d %H:%M:%S")))

time  :
# time.time()
# time.sleep()
# time.gmtime() / time.localtime() #
# time.strftime("   ","     ") #
# time.strptime("   ","   ")
# time.mktime()

# "2019-10-14 17:30:20"     

3.datetimeモジュール
# from datetime import datetime,timedelta

# datetime --   
# print(type(datetime.now()))

# print(datetime.now()) #       
# print(datetime(2019,5,20,15,14,00) - datetime(2019,5,20,14,20,00))

#            
# t = datetime.now()
# print(t.timestamp())

#            
# import time
# print(datetime.fromtimestamp(15000000000))

#         
# print(type(datetime.strptime("2019-10-10 22:23:24","%Y-%m-%d %H:%M:%S")))

#         
# print(str(datetime.now()))
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))


# datetime  
# print(datetime.now() + timedelta(hours=30 * 24 * 12))
# print(datetime.now() - timedelta(hours=30 * 24 * 12))


#   :time
#       :        
#         

4.randomモジュール
# import random

# print(random.random())          # 0 ~ 1
# print(random.uniform(1,10))     # 1 ~ 10
# print(random.randint(1,50))     # 1 ~ 50(   )
# print(random.randrange(1,5,2))    # randrange(  ,  ,  )
# print(random.choice([1,2,3,4,5,])) #       
# print(random.choices([1,2,3,4,5,],k=2))   #       ,    
# print(random.sample((1,2,3,4,5),k=2))  #       ,     (      )

# lst = [1,2,3,4,5,6,7,8,9,0]
# random.shuffle(lst)  #     
# print(lst)

#   :   

5.今日のまとめ
# 1.     
#     import    
#     from     import   
#     from     import *
#     __all__ = ["func","name"]  #   *     
      #     import from

      #        :
          # if __name__ == '__main__':
          #             ,if        
          #               if         

      #       :

      #        :
      #     :
            # from    .    import   
      #     :
      #     from sys import path
      #     path.insert(0,    )
      #     >    >    

# 2.time
    # time.time()   #        
    # time.sleep()  #       
    # time.gmtime() / time.localtime() #     --    
    # time.strftime("   ","     ") #      -     
    # time.strptime("   ","   ") #     -    
    # time.mktime() #     --    

# 3.datetime
    #            
    # t = datetime.now()
    # print(t.timestamp())

    #            
    # import time
    # print(datetime.fromtimestamp(15000000000))

    #         
    # print(type(datetime.strptime("2019-10-10 22:23:24","%Y-%m-%d %H:%M:%S")))

    #         
    # print(str(datetime.now()))
    # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))


    # datetime  
    # print(datetime.now() + timedelta(hours=30 * 24 * 12))
    # print(datetime.now() - timedelta(hours=30 * 24 * 12))

# 4.random (   )

    # print(random.random())          # 0 ~ 1
    # print(random.uniform(1,10))     # 1 ~ 10
    # print(random.randint(1,50))     # 1 ~ 50(   )
    # print(random.randrange(1,5,2))    # randrange(  ,  ,  )
    # print(random.choice([1,2,3,4,5,])) #       
    # print(random.choices([1,2,3,4,5,],k=2))   #       ,    
    # print(random.sample((1,2,3,4,5),k=2))  #       ,     (      )

    # lst = [1,2,3,4,5,6,7,8,9,0]
    # random.shuffle(lst)  #     
    # print(lst)

転載先:https://www.cnblogs.com/liubing8/p/11263587.html