syntax:import module
math:
import math
print(math.sqrt(25)) #5.0
print(math.factorial(5)) #120
or
from math import sqrt,factorial
print(sqrt(25)) #5.0
print(factorial(5)) #120
import all names from module use --> *
from math import *
print(sqrt(25)) #5
print(factorial(5)) #120
Renaming the module:
import math as m
print(m.sqrt(36)) #6
print(m.factorial(4)) #24
Random number:
import random
print(random.randint(4,55))
calendar:
import calendar
print (calendar.calendar(2022))
No comments:
Post a Comment