# 1 — the whole module
import math
math.sqrt(16) # 4.0
# 2 — with an alias (the convention for big libraries)
import pandas as pd
pd.read_csv("file.csv")
# 3 — a specific name
from math import sqrt, pi
sqrt(16) # 4.0
pi # 3.14159...
math, os, pathlib, datetime, json, csv, re.pip install .... Examples: pandas, numpy, openpyxl, requests.| Library | Conventional alias |
|---|---|
| pandas | import pandas as pd |
| numpy | import numpy as np |
| matplotlib.pyplot | import matplotlib.pyplot as plt |
| seaborn | import seaborn as sns |
Use the conventions. Strangers reading your code will thank you.
Any .py file is automatically importable from a script in the same folder. Put related functions in helpers.py:
# helpers.py
def clean_email(s):
return s.strip().lower()
Then in main.py next to it:
from helpers import clean_email
clean_email(" ALICE@example.com ") # 'alice@example.com'
import x / import x as y / from x import y — three styles.pip install..py files is importable.Use the datetime module to print today's date in the format YYYY-MM-DD. Hint: from datetime import date; date.today().isoformat().