Getting Started
What is Python?¶
Python is a high-level general-purpose programming language. It is widely known because it is efficient and easy to learn. Contextualizing it, Python is a powerful tool for:
Data Cleaning: Automating the processing of thousands of survey records.
Analysis: Calculating crop yields, poverty incidence, and other statistics.
Geospatial Processing: Analyzing farm locations and land use.
You can read more about Python here: AWS: What is Python?
Kumusta mundo!¶
print("Kumusta mundo!")Output
Kumusta mundo!
Libraries and Modules¶
What are libraries?¶
A collection of pre-written code and functionalities that can be reused in other applications/scripts
Saves time and effort by providing ready-made solutions for common tasks
DRY principle - DON’T REPEAT YOURSELF
Comes bundled with Python and includes a wide range of modules for various tasks.
Examples include math for mathematical operations and os for interacting with the operating system.
Third-Party Libraries
Developed by the Python community or external developers.
Extend Python’s functionality beyond the standard library.
Examples include:
Where to find? Try PyPI the Python Package Index.
How to Import a Library in Python?¶
We use the import keyword to bring a tool into our script.
| Command | Explanation |
|---|---|
import math | Imports the whole toolbox. You use it like math.sqrt(). |
import pandas as pd | Imports it but gives it a nickname (pd) to save typing. |
from math import sqrt | Imports only one specific tool. |
from math import * | Imports everything blindly. |
Source: Adapted from Python 3 Documentation: Modules
# Standard Library: Import math module
import math
num = 25
result = math.sqrt(num)
print(result)Output
5.0
# Import the srqt function from the math module
from math import sqrt
num = 25
result = sqrt(num)
print(result)Output
5.0
# Import everything from the math module
from math import *
num = 25
result = sqrt(num)
print(result)Output
5.0
Please avoid using the last method above. While this approach works, it is not recommended. Why do you think so?
# Rename while importing for easier typing later
import datetime as dt
print(dt.date.today())Output
2026-01-13
# Will this work?
from datetime import date as d8Output
How will you get today’s date?
# Write your solution here