# Python Built-in Modules

Lesson Progress
0% Complete

Modules – math

``````import math

print(math.pi)
# Pie (π) is a mathematical constant
print(math.e)
# Euler's number
print(math.log(10))
# natural logarithm is calculated to the base e.
print(math.log10(10))
# returns the base-10 logarithm
print(math.pow(2,10))
# method receives two arguments float, raises the first to the second and returns the result
print(math.sqrt(10000))
# method returns the square root
``````

Modules – random

``````import random
# Generates a random float number between 0.0 to 1.0.
print(random.random())
# Generates a random number between the specified integers.
print(random.randint(1,100))
# randomly selected element from a non-empty sequence
print(random.choice([12,23,45,67,65,43]))
# randomly reorders the elements in a list.
my_list = [3,8,12,23,37,45,67,65,43]
random.shuffle(my_list)
print(my_list)
``````

Module – datetime

``````import datetime

current_t = datetime.datetime.now()
print(current_t)
print(type(current_t))
``````

Module – strftime()

``````import datetime
new_year = datetime.datetime(2020, 1, 1) # new year date
#  strftime() Method
print('Month: ',new_year.strftime("%B"))
print('Day: ',new_year.strftime("%A"))
print('Date: ',new_year.strftime("%d"))
print('Year: ',new_year.strftime("%Y"))
print('Month number: ',new_year.strftime("%m"))
``````