Learn Python 3 - Modules Reference Guide - Codecademy
Learn Python 3 - Modules Reference Guide - Codecademy
Learn Python 3
Modules
Print cheatsheet
It allows you to set date , time or both date and time using the
date() , time() and datetime() functions respectively, after importing the
datetime module .
import datetime
feb_16_2019 = datetime.date(year=2019, month=2, day=16)
feb_16_2019 = datetime.date(2019, 2, 16)
print(feb_16_2019) #2019-02-16
# Aliasing calendar as c
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-modules/cheatsheet 1/3
10/03/2020 Learn Python 3: Modules Reference Guide | Codecademy
import calendar as c
print(c.month_name[1])
Modules can be imported in three different ways: import module , from module
import functions , or from module import * . from module import * is
discouraged, as it can lead to a cluttered local namespace and can make the
namespace unclear.
# Second way
from module import function
function()
# Third way
from module import *
function()
# Returns a random integer N in a given range, such that start <= N <=
end
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-modules/cheatsheet 2/3
10/03/2020 Learn Python 3: Modules Reference Guide | Codecademy
# random.randint(start, end)
r1 = random.randint(0, 10)
print(r1) # Random integer where 0 <= r1 <= 10
Module importing
In Python, you can import and use the content of another le using import
filename , provided that it is in the same folder as the current le you are
writing.
# file1 content
# def f1_function():
# return "Hello World"
# file2
import file1
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-modules/cheatsheet 3/3