Python

Python Modules and datetime

Python module can have code with variables, functions and classes 

Create a module:
def fn(num):
   return num*2
Save the above code in module1.py

import module:
import module1
n=module1.fn(2)
print(n)

Output: 4

Use built in module:
import math
n=math.sqrt(16)
print(n)

Output: 4

strftime(): returns a string of date and time using date or time object

import datetime
dtm=datetime.datetime.now()
print(dtm)    output: 2022-03-11 15:54:02.989652

print(dtm.year)   output: 2022
print(dtm.strftime(“%m/%d/%Y”))  output: 03/11/2022
print(dtm.strftime(“%b %d %Y”))   output: Mar 11 2022

Add 10 days to current date:

from datetime import timedelta, datetime
print(datetime.now()+timedelta(days=10))