close

Introduction to Python Programming

June 29, 2025 · By @mritxperts
Introduction to Python Programming

Total Hours: 10 | Marks: 5


What is Python?

Python is a simple, beginner-friendly, and powerful programming language. It is used to build websites, apps, games, Artificial Intelligence, and more.

Python is one of the most popular languages in the world because:


Why Learn Python in AI?

Python is the most commonly used programming language in Artificial Intelligence. It helps in:

Python is a good first language for students to start coding.


Writing Your First Python Program

The print() Function

print() is used to display a message on the screen.

Example:

pythonCopyEditprint("Hello, AI World!")

Output:

CopyEditHello, AI World!

Getting Input from the User

We can use the input() function to ask the user to type something.

Example:

pythonCopyEditname = input("What is your name? ")
print("Hello, " + name)

Output:

pgsqlCopyEditWhat is your name? Riya
Hello, Riya

Variables in Python

A variable is like a container that stores data (like numbers or text).

Example:

pythonCopyEditage = 15
name = "Arjun"
print(name + " is " + str(age) + " years old.")

Output:

pgsqlCopyEditArjun is 15 years old.

Data Types

Python has different types of data:

Data TypeExample
String“Hello”, “AI”
Integer5, 100, -45
Float3.14, 9.8
BooleanTrue, False
List[1, 2, 3]

Operators in Python

Operators are symbols used to perform operations like addition, subtraction, etc.

OperatorMeaningExample
+Addition5 + 2 = 7
-Subtraction10 – 4 = 6
*Multiplication3 * 4 = 12
/Division8 / 2 = 4.0
==Equal to5 == 5 → True
!=Not equal to5 != 3 → True
<, >Less/Greater4 > 3 → True

if-else Statements

These are used to make decisions in programs.

Example:

pythonCopyEditmarks = 75
if marks >= 33:
    print("Pass")
else:
    print("Fail")

Output:

nginxCopyEditPass

Loops in Python

Loops are used to repeat actions.

1. for Loop

Used to repeat actions a fixed number of times.

Example:

pythonCopyEditfor i in range(5):
    print("AI is fun!")

Output:

kotlinCopyEditAI is fun!
AI is fun!
AI is fun!
AI is fun!
AI is fun!

2. while Loop

Used when we don’t know how many times to repeat, but we have a condition.

Example:

pythonCopyEditcount = 1
while count <= 3:
    print("Welcome!")
    count = count + 1

Lists in Python

A list is a group of items stored together.

Example:

pythonCopyEditfruits = ["apple", "banana", "orange"]
print(fruits[0])  # Output: apple

Lists are very useful when working with large amounts of data, such as AI datasets.


Suggested Classroom Activities and Practicals

1. Grade Checker Program

Ask students to write a program that takes marks and prints pass or fail.

pythonCopyEditmarks = int(input("Enter your marks: "))
if marks >= 33:
    print("You Passed!")
else:
    print("You Failed.")

2. Sum of Two Numbers

pythonCopyEdita = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("The sum is:", a + b)

3. List Average Program

pythonCopyEditnumbers = [60, 70, 80]
average = sum(numbers) / len(numbers)
print("Average is:", average)

4. Even or Odd Checker

pythonCopyEditnum = int(input("Enter a number: "))
if num % 2 == 0:
    print("Even")
else:
    print("Odd")

Summary of the Unit