
Python for AI/ML – Episode 2
Understanding Python Basics for Artificial Intelligence and Machine Learning
In the previous episode, we successfully installed Python and set up the development environment required for Artificial Intelligence and Machine Learning projects. Now, in Episode 2, we will begin learning the fundamentals of Python programming that form the backbone of AI and ML development.
Python is one of the most popular programming languages in the world because of its simple syntax, readability, and massive collection of libraries. Most AI and ML frameworks such as TensorFlow, PyTorch, Scikit-learn, and Pandas are built using Python. Therefore, understanding Python basics is the first step toward becoming an AI/ML developer.
Why Python for AI and ML?
Python is widely used in AI and ML because:
Due to these advantages, companies and researchers prefer Python for building intelligent systems.
Writing Your First Python Program
The first program most beginners write is the “Hello World” program.
print("Hello World")

Image
Printing in Python
Printing means displaying output on the screen. Python uses the print() function to show messages, values, and results.
Syntax of print()
print("Hello")
Printing Text
Text must be written inside quotes.
Example
print("Hello World")
Output
Hello World
Printing Numbers
Numbers can be printed without quotes.

Image
image showing printing numbers in python
Variables in Python
Think of a variable as a labeled storage box. In Python, you use these boxes to store data so you can refer to it later by name.
Unlike some other languages, Python is "dynamically typed," which means you don’t have to tell the computer what kind of data is going inside the box ahead of time. You just give it a name and assign a value.
1. The Anatomy of a Variable
To create a variable, you follow a simple pattern: name = value.

Image
image showing variable types
Variable Properties
1. Variable Name Rules
A variable name:
Correct

Image
Wrong
1name = "Alex"student name = "Alex"
2. Case-Sensitive
Python treats uppercase and lowercase differently.
age = 20
Age = 30
Here:
3. No Reserved Keywords
Python keywords cannot be used as variable names.
Wrong
class = 10for = 5
Because:
are already used by Python.
4. No Spaces
Variable names cannot contain spaces.
Wrong
student name = "Chipset"
Correct
student_name = "Chipset"
Underscores _ are used instead of spaces.
5. Dynamic Typing
Python automatically decides the type of variable.
x = 10x = "Python"
First:
Later:
Python allows changing data types dynamically.
6. Memory Allocation
When a value is assigned to a variable, Python stores it in memory.
name = "AI"
Here:
2. Basic Data Types
Variables can hold different "flavors" of data. Here are the most common ones you'll use:

Image
an image on data types and their properties in python
1. Integer (int)
Integers are whole numbers.
x = 10
Properties
Examples
a = 100b = -25
2. Float (float)
Floats are decimal numbers.
pi = 3.14
Properties
Examples
height = 5.8temperature = 36.5
3. String (str)
Strings store text.
name = "Danesh"
Properties
Examples
city = "Chennai"
course = "Python"
4. Boolean (bool)
Booleans represent logical values.
is_active = True
Properties
Examples
is_logged_in = False
whatever we saw till now are primitive data types we will explore further on other data types in coming episodes
Checking Data Types
We can check the type using type().
Example

Image
image showing o/p on type() function
Comments in Python
Comments are notes written inside a program to explain the code. Python ignores comments during execution.
Comments help to:
Types of Comments in Python
Single-Line Comments
Single-line comments start with #.
Syntax
# This is a comment

Image
this image shows how the program ignores comment lines and prints output
Multi-Line Comments
Triple quotes are commonly used for multi-line comments.
Syntax
"""This is a multi-line comment"""

Image
example showing multi-line comments
Printing Variables
As seen Above variables can printed very easily in python

Image
image depicting printing variables
Printing Multiple Values
Multiple values can be printed using commas.

Image
Using Separator (sep)
The sep parameter changes the separator between values.

Image
Image showing usage of sep
Using End (end)
The end parameter changes the ending character.

Image
Overall printing functions are shown below

Image
Input in Python
Input means taking data from the user while the program is running. In Python, the input() function is used to receive values from the keyboard.
This makes programs interactive because the user can give different values every time the program runs.
Syntax:
input("Message")
The text inside quotes is shown to the user. Whatever the user types is returned by the input() function.
Basic Input Example

Image
Output
Enter your name: chipset
chipset
Explanation
Input with a Message
Usually, we display a message so the user understands what to enter.

Image
Important Point About input()
By default, Python stores all input values as strings (str).
Even if the user enters a number, Python treats it as text.

Image
image showing default input type
Why Type Conversion is Needed
Suppose we take two numbers as input:
a = input("Enter first number: ")
b = input("Enter second number: ")
print(a + b)
Output
1020
Explanation
Python joins the strings instead of adding them mathematically.
So, we need type conversion.
Integer Input using int()
The int() function converts input into an integer.

Image
image showing integer input
Explanation
Float Input using float()
The float() function converts input into decimal numbers.
Example
height = float(input("Enter height: "))
print(height)
Output
Enter height: 5.85.8
Taking Multiple Inputs
We can take multiple values from the user.
Example
name = input("Enter name: ")
age = int(input("Enter age: "))
print(name, age)
Output
Enter name: chipset
Enter age: 19
chipset 19
Real-Life Uses of Input
Input is used in:
Almost every interactive application uses input functions.
Homework
Try these programs on your own to improve your understanding of Python basics:
Conclusion
In this article, we learned the basic fundamentals of Python programming, including:
These concepts form the foundation of Python programming and are essential for Artificial Intelligence and Machine Learning development.
Keep practicing these basics regularly, because strong fundamentals make advanced programming much easier to learn.
Stay tuned for the next episode to explore more Python concepts and continue your journey into AI and Machine Learning.
Written by Chakradhar on May 13, 2026
