Skip to content
techsnow

Functions

Modules and Imports

A module is a file of Python code you can reuse. Python comes with many built in (the standard library).

import random
from math import sqrt, pi
from datetime import date
import json as js

print(random.choice(["rock", "paper", "scissors"]))
print(sqrt(16), round(pi, 2))
print(date.today())

Your own module

# helpers.py
def add(a, b):
    return a + b

# main.py
from helpers import add
print(add(2, 3))