If you find the content useful and wish to support our platform’s development, you can contribute any amount toward our production costs. Scan the UPI QR code for payment within India. Or use the Ko-fi link to process a secure payment via PayPal.
If you find the content useful and wish to support our platform’s development, you can contribute any amount toward our production costs. Scan the UPI QR code for payment within India. Or use the Ko-fi link to process a secure payment via PayPal.
Imagine that you have just been hired as a junior AI Engineer. On your first day, your manager asks you to build a simple application that reads customer information, sends a question to an AI model, and displays the AI's response.
What programming language would you choose?
Today, most AI engineers would answer with one word: Python.
Python has become the most widely used programming language in Artificial Intelligence, Machine Learning, Data Science, Scientific Computing, Automation, and many other fields. Whether you are building a chatbot, analysing medical data, developing an autonomous robot, or creating an intelligent recommendation system, there is a very good chance that Python is being used somewhere in the project.
But Python did not become popular simply because it is powerful. It became popular because it allows developers to solve complex problems using code that is clean, readable, and relatively easy to learn.
Throughout this module, you will begin writing Python programs from scratch. You will learn how computers store information, make decisions, repeat tasks, organise code, and interact with files. More importantly, you will begin thinking like a programmer—a skill that every AI engineer must develop.
By the end of this module, you will have written your own Python programs and built your first mini-project, providing a solid programming foundation for the AI, Machine Learning, and Data Science modules that follow.
Artificial Intelligence requires developers to process large amounts of data, perform mathematical calculations, build predictive models, and interact with sophisticated software libraries.
Python makes all of these tasks easier.
Because of these advantages, companies ranging from startups to global technology organizations use Python extensively in their AI projects.
Python is used in many different industries.
| Industry | Example Applications |
|---|---|
| Healthcare | Disease prediction, medical imaging, clinical decision support |
| Finance | Fraud detection, algorithmic trading, risk analysis |
| Education | Intelligent tutoring systems, automated grading |
| Retail | Product recommendations, demand forecasting |
| Manufacturing | Predictive maintenance, quality control |
| Agriculture | Crop monitoring, disease detection |
| Cybersecurity | Threat detection, malware analysis |
| Scientific Research | Data analysis, simulations, statistical modelling |
As you can see, learning Python is not simply learning another programming language. It is acquiring a skill that is valuable across many professional domains.
Learn more about Machine Learning and Deep Learning in our AI Guide series.
Before writing your first program, you need a place where Python code can be written and executed.
In the previous module, you learned about two important development environments:
Both can run Python programs, but each serves a slightly different purpose. Professional AI engineers often use both depending on the task they are performing.
Visual Studio Code is one of the world's most popular development environments. It allows developers to create complete software projects consisting of many files, folders, and libraries.
Typical uses include:
VS Code is especially useful when your projects become more complex.
Google Colab provides an online notebook environment. Instead of installing software locally, your code runs on Google's cloud infrastructure.
Colab is particularly useful for:
| Visual Studio Code | Google Colab |
|---|---|
| Professional software development | Interactive notebooks |
| Local computer | Cloud platform |
| Large projects | Experiments and learning |
| Best for production code | Best for exploration |
| Git integration | Google Drive integration |
The answer is simple:
Use both.
During this course, small experiments can be performed in Google Colab, while larger projects should be developed in Visual Studio Code. Learning both environments prepares you for a wide variety of professional workflows.
print("Hello LearnerBox!")
Imagine you are building an AI assistant for a university.
Every time a student asks a question, the program must remember:
Where does the program store all of this information?
The answer is:
Variables.
Variables are one of the most fundamental concepts in programming. Almost every program you will ever write, from a simple calculator to a sophisticated AI agent, relies on variables to temporarily store information while the program is running.
You can think of a variable as a labelled container. Instead of writing information directly into your program every time you need it, you store it inside a variable and refer to that variable whenever required. Variables allow AI systems to store information such as user input, predictions, or model parameters.
name = "Aisha"
age = 22
course = "AI Engineer"
completed = True
Python automatically determines the type of data stored in each variable.
| Data Type | Example | Purpose |
|---|---|---|
| Integer | 25 |
Whole numbers |
| Float | 98.75 |
Decimal numbers |
| String | "Hello" |
Text |
| Boolean | True |
True/False values |
Good variable names improve readability.
Good examples:
student_name
course_fee
total_marks
ai_model
Poor examples:
a
x1
temp2
data1234
Choose names that describe the information being stored.
Unlike some programming languages, Python allows variables to change their type.
age = 20
age = "Twenty"
Although Python permits this, changing variable types unnecessarily can make programs difficult to understand.
= with the equality operator ==. score = 90
assigns a value, while score == 90 checks whether two values are equal.
print() function.
Imagine you are developing an AI application that predicts whether a student qualifies for a scholarship.
The application needs to calculate averages, compare grades, determine eligibility, and combine several conditions before making a recommendation.
How does Python perform these calculations and comparisons?
The answer lies in operators.
Operators are symbols that instruct Python to perform actions on data. Just as mathematical operators such as + and − allow us to perform arithmetic, Python provides several types of operators for calculations, comparisons, logical decisions, and more.
| Operator | Purpose | Example |
|---|---|---|
| + | Addition | 5 + 3 |
| - | Subtraction | 8 - 2 |
| * | Multiplication | 6 * 7 |
| / | Division | 20 / 4 |
| // | Floor Division | 20 // 3 |
| % | Modulus | 20 % 3 |
| ** | Exponent | 2 ** 5 |
price = 1500
tax = 270
total = price + tax
print(total)
| Operator | Meaning |
|---|---|
| == | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
marks = 82
print(marks >= 50)
| Operator | Meaning |
|---|---|
| and | Both conditions must be true |
| or | At least one condition must be true |
| not | Reverses the result |
age = 21
graduate = True
print(age >= 18 and graduate)
subjects = ["Maths","Statistics","Python"]
print("Python" in subjects)
a = [1,2,3]
b = a
print(a is b)
Identity operators are used less frequently by beginners but become important in advanced Python programming.
= assigns a value, whereas
== compares two values.
Programming becomes much more interesting when users can interact with our programs.
So far, we have only displayed information using the
print() function.
Real applications also accept information from users.
This is called input.
print("Welcome to LearnerBox")
name = input("Enter your name: ")
print("Welcome", name)
age = int(input("Enter your age: "))
price = float(input("Enter the price: "))
name = "Aisha"
print(f"Welcome {name}")
Suppose you are developing an AI system for an online examination.
The system must determine whether a student passed, whether a loan application should be approved, whether an email is spam, or whether a customer receives a discount.
How does software make these decisions?
Through conditional statements.
Conditional statements allow programs to choose different actions depending on conditions.
marks = 82
if marks >= 50:
print("Pass")
marks = 42
if marks >= 50:
print("Pass")
else:
print("Fail")
marks = 75
if marks >= 90:
print("Excellent")
elif marks >= 75:
print("Very Good")
elif marks >= 50:
print("Pass")
else:
print("Fail")
age = 22
graduate = True
if age >= 18:
if graduate:
print("Eligible")
if age >= 18:
print("Adult")
Imagine you are developing an AI application that must analyse one thousand customer reviews.
Would you write the same piece of code one thousand times?
Of course not. Instead, you tell the computer: repeat this task for every review.
This is exactly what loops allow us to do. AI applications frequently process thousands or millions of records. Loops automate repetitive tasks efficiently.
for number in range(5):
print(number)
languages = ["Python", "SQL", "R"]
for language in languages:
print(language)
count = 1
while count <= 5:
print(count)
count += 1
for number in range(10):
if number == 5:
break
print(number)
for number in range(5):
if number == 2:
continue
print(number)
while loop, creating an infinite loop.
for loop.
Imagine building an AI chatbot containing one thousand lines of code. Suppose the chatbot needs to greet users. Would you write the greeting code fifty different times?
Professional programmers avoid repetition. Instead, they create functions.
A function is a reusable block of code that performs a specific task.
def greet():
print("Welcome to LearnerBox")
greet()
def greet(name):
print(f"Welcome {name}")
greet("Aisha")
def square(number):
return number ** 2
answer = square(8)
print(answer)
Variables created inside a function usually exist only within that function.
def demo():
message = "Hello"
Suppose you are building an AI assistant for a university. The assistant needs to store student names, examination marks, course information, departments, and attendance records.
Using separate variables for every piece of information would quickly become impossible. Instead, Python provides data structures. Choosing the right data structure makes AI programs easier to understand and more efficient.
students = ["Aisha", "Rahul", "Fatima"]
Lists are ordered, changeable, and allow duplicates.
coordinates = (15.2, 27.8)
Tuples are useful when information should remain constant.
subjects = {"Python", "Statistics", "AI"}
Sets store unique values and automatically remove duplicates.
student = {
"name": "Aisha",
"marks": 91,
"course": "AI Engineer"
}
Dictionaries store information as key-value pairs and are heavily used in AI applications.
| Structure | Ordered | Changeable | Duplicates |
|---|---|---|---|
| List | Yes | Yes | Yes |
| Tuple | Yes | No | Yes |
| Set | No | Yes | No |
| Dictionary | Yes | Yes | Keys unique |
Imagine you are building an AI application that analyses customer feedback stored in a text file. Before the AI model can process the information, your Python program must first read the file.
file = open("notes.txt", "r")
file = open("notes.txt", "r")
content = file.read()
print(content)
file.close()
file = open("notes.txt", "w")
file.write("Welcome to LearnerBox!")
file.close()
file = open("notes.txt", "a")
file.write("\nPython is fun!")
file.close()
with open("notes.txt", "r") as file:
content = file.read()
print(content)
with statement instead of manually
calling close().
my_notes.txt. Write three reasons why
you want to learn AI. Then write a Python program that reads and displays the file.
No programmer writes perfect code. Even experienced AI engineers make mistakes every day. The difference is that experienced developers know how to identify and handle errors effectively.
An exception occurs whenever Python encounters an unexpected situation.
try:
number = int(input("Enter a number: "))
print(number)
except:
print("Invalid input")
try:
number = int(input())
except ValueError:
print("Please enter a valid number.")
try:
print("Running program")
finally:
print("Program finished")
except: whenever possible. Catch specific
exceptions to make debugging easier.
One of Python's greatest strengths is its enormous ecosystem of libraries. Instead of writing everything yourself, you can use software written by other developers.
Libraries allow developers to build upon existing work instead of starting from scratch.
pip install pandas
pip install numpy
import pandas
import numpy as np
| Library | Purpose |
|---|---|
| NumPy | Numerical computing |
| Pandas | Data analysis |
| Matplotlib | Data visualization |
| Scikit-learn | Machine Learning |
| TensorFlow | Deep Learning |
| PyTorch | Deep Learning |
| OpenAI SDK | Building AI applications |
| LangChain | LLM application development |
| FastAPI | Building APIs |
You will soon work with libraries such as NumPy, Pandas, and Matplotlib in Module 3.
In this mini project, you will combine many of the concepts learned in this module.
Write a Python program that:
Upload this project to the GitHub repository you created in Module 1 and write a short README describing:
Congratulations! You have completed your first Python programming module.
More importantly, you have begun developing the mindset of a software engineer.
You can now write Python programs that solve problems. In the next module, you will apply those programming skills to real-world datasets, discovering how AI engineers clean, analyse, and visualize data before building machine learning models.
Take a few minutes to think about your learning.
for loop and a while loop?try and except statements?Take a short Quiz and find your score. You can always come back to this page and go through the content again!