Learn Python 3_ Modules Cheatsheet _ Codecademy
Learn Python 3_ Modules Cheatsheet _ Codecademy
Modules
time_13_48min_5sec =
datetime.time(hour=13, minute=48,
second=5)
time_13_48min_5sec = datetime.time(13,
48, 5)
print(time_13_48min_5sec) #13:48:05
timestamp= datetime.datetime(year=2019,
month=2, day=16, hour=13, minute=48,
second=5)
timestamp = datetime.datetime(2019, 2,
16, 13, 48, 5)
print (timestamp) #2019-01-02 13:48:05
# Aliasing calendar as c
import calendar as c
print(c.month_name[1])
Import Python Modules
The Python import statement can be used to import # Three different ways to import modules:
Python modules from other files.
# First way
Modules can be imported in three different ways:
import module , from module import import module
functions , or from module import * . module.function()
from module import * is discouraged, as it
can lead to a cluttered local namespace and can make
# Second way
the namespace unclear.
from module import function
function()
# Third way
from module import *
function()
Module importing
In Python, you can import and use the content of # file1 content
another file using import filename , provided
# def f1_function():
that it is in the same folder as the current file you are
writing. # return "Hello World"
# file2
import file1
Print Share