Key Learning Outcomes
By the end of the lesson “Programming in Python”, readers will:
- Understand the Concept of Python Programming
- Setting Up Python
- Basic Terms Comments, Variables, Data Types, etc.
- Understand Operators in Python
- Basic Code
- Solve Some Practice Questions
Click On The Name To Go To A Specific Topic:
Introduction
Python is a high-level, interpreted programming language known for its simplicity and readability. It is widely used in web development, data science, artificial intelligence, and automation.
- Easy to learn and write
- Interpreted language (Executes line by line)
- Supports multiple paradigms (Procedural, Object-Oriented, Functional)
- Extensive library support
Why Learn Python?
- Simple syntax similar to English
- Used by companies like Google, Facebook, NASA
- Great for beginners and professionals
Example of a simple Python program:
print("Welcome to Python Programming!")This will output: Welcome to Python Programming!
Setting Up Python
To start coding in Python, you need to install Python and use an IDE (Integrated Development Environment) like:
- IDLE (Comes with Python)
- VS Code
- PyCharm
- Jupyter Notebook
Writing and Running Python Code
Python code can be written and executed in three ways:
- Using Python Interpreter (IDLE)
- Using a Python Script (.py file)
- Using an Online Compiler (Google Colab, Replit, etc.)
Comments in Python
Comments are used to explain the code and are ignored by the interpreter.
1. Single-Line Comment:
# This is a single-line comment
print("Hello, Python!")  # This prints a message2. Multi-Line Comment:
For multi-line comments, use triple quotes:
"""
This is a 
multi-line comment
"""Variables in Python
A variable is a name given to a memory location where data is stored.
π‘ Python is dynamically typed (No need to declare the type explicitly).
Declaring Variables
name = "Alice"  # String
age = 12        # Integer
height = 5.4    # Float
is_student = True  # Boolean
- Variable names should start with a letter (A-Z, a-z) or underscore (_)
- Should not use keywords like print,class,if, etc.
Data Types in Python
Python provides several data types to store different kinds of values.

Example:
x = 10        # Integer
y = 3.14      # Float
name = "John" # String
is_valid = True # Boolean
fruits = ["Apple", "Banana", "Cherry"]  # ListType Conversion (Type Casting)
Python allows conversion of one data type to another.
Implicit Type Conversion
Python automatically converts a smaller data type to a larger data type.
num = 5   # Integer
num = num + 2.5  # Now it becomes float (7.5)
print(type(num))  # Output: <class 'float'>Explicit Type Conversion
We can manually convert types using int(), float(), str(), bool().
a = "123"
b = int(a)  # Convert string to integer
print(b)  # Output: 123Input and Output in Python
- input()function is used to take user input.
- print()function is used to display output.
Example:
name = input("Enter your name: ")
print("Hello, " + name + "!")If the user enters “Adam”, the output will be:
Hello, Adam!
Operators in Python
Operators are used to perform operations on variables and values.
1. Arithmetic Operators

Example:
a = 10
b = 5
print(a + b)  # Output: 15
print(a ** b)  # Output: 100000 (10^5)2. Comparison Operators
a = 10
b = 20
print(a == b)  # False
print(a != b)  # True
print(a < b)   # True
print(a > b)   # False
3. Logical Operators
x = True
y = False
print(x and y)  # False
print(x or y)   # True
print(not x)    # FalseConditional Statements (if-else)
Conditional statements allow decision-making in programs.
age = 18
if age >= 18:
    print("You are eligible to vote.")
else:
    print("You are not eligible to vote.")
if-elif-else Example
marks = 85
if marks >= 90:
    print("Grade: A+")
elif marks >= 75:
    print("Grade: A")
else:
    print("Grade: B")
Loops in Python (for & while)
Loops are used to execute a block of code multiple times.
For Loop (Definite Iteration)
for i in range(1, 6):
    print(i)  # Output: 1 2 3 4 5While Loop (Indefinite Iteration)
num = 1
while num <= 5:
    print(num)  # Output: 1 2 3 4 5
    num += 1Loop Control Statements
- breakβ Exit the loop
- continueβ Skip the current iteration
- passβ Placeholder
Example:
for i in range(1, 6):
    if i == 3:
        continue  # Skips 3
    print(i)  # Output: 1 2 4 5Important Summary Points
- Python is an easy and powerful language
- Variables store data dynamically
- Different data types: int, float, str, bool, list, tuple, dict
- Type conversion allows changing data types
- Operators perform mathematical operations
- Variables & Data Types β Store and manage data.
- Operators β Perform calculations & comparisons.
- Conditionals & Loops β Control program flow.
- Functions β Reuse code.
- Lists, Tuples, Dictionaries β Store and manage collections.
- File Handling β Read and write files.
- Exception Handling β Manage errors.
- OOP Concepts β Organize code into reusable classes.
Interesting Facts About Integers
- Created by Guido van Rossum β Python was developed in 1989 and released in 1991.
- Named after Monty Python β The name “Python” was inspired by the British comedy show Monty Python’s Flying Circus, not the snake!
- Interpreted Language β Python executes code line by line, making debugging easier.
- Dynamically Typed β No need to declare data types; Python automatically assigns them.
- Indentation Matters β Unlike other languages that use
{}or;, Python uses indentation (spaces/tabs) to define blocks of code.- Multi-Purpose Language β Python is used in AI, web development, data science, automation, cybersecurity, gaming, and more!
- Huge Library Support β Python has thousands of built-in libraries like
numpy,pandas,matplotlib,tensorflow, anddjangofor various applications.- Cross-Platform Compatibility β Python runs on Windows, macOS, Linux, and even mobile devices!
- Most Popular Programming Language β According to the TIOBE Index, Python is consistently ranked as the #1 most used language.
- Used by Tech Giants β Python is used by Google, Facebook, Instagram, NASA, Netflix, YouTube, and even NASA for space missions!
- Simple Yet Powerful β Pythonβs syntax is similar to English, making it beginner-friendly while still being powerful enough for complex applications.
- Supports Object-Oriented and Functional Programming β Python allows both OOP and functional programming, giving developers flexibility.
- Large Community Support β Being open-source, Python has a massive global community, making it easy to find solutions and resources online.
- Python is used in Machine Learning & AI β Libraries like TensorFlow, Scikit-learn, and PyTorch make it the top choice for AI research.
- Famous Apps Built with Python β Apps like YouTube, Instagram, Spotify, Reddit, and Dropbox are built using Python.

Practice Questions with Solutions:
1. Print your name, age, and favorite hobby using separate print() statements.
print("Hello, Python!")
print("My name is Laiba.")
print("I am 14 years old.")
print("My favorite hobby is painting.")2. Declare three variables: name, age, and height, and print them.
# Assign values to variables
name = "Laiba"
age = 14
height = 5.4
# Print variables
print(name, age, height)
# Check data types
x = 10       # Integer
y = 5.5      # Float
z = "Hello"  # String
print(type(x))  # Output: <class 'int'>
print(type(y))  # Output: <class 'float'>
print(type(z))  # Output: <class 'str'>3. Write a program that asks the user for their name and age and then prints a message like:
"Hello, Habiba! You are 12 years old."
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Hello,", name + "! You are", age, "years old.")4. Write a Python program to add, subtract, multiply, and divide two numbers entered by the user.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Remainder when 15 is divided by 4:", 15 % 4)5. Convert the string "123" to an integer and multiply it by 2.
x = 10
y = str(x)  # Convert integer to string
print(y, type(y))
s = "123"
num = int(s)  # Convert string to integer
print(num * 2)  # Output: 2466. Write a program to check if a number is even or odd.
# Check even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
    print(num, "is Even")
else:
    print(num, "is Odd")
# Check voting eligibility
age = int(input("Enter your age: "))
if age >= 18:
    print("You are eligible to vote.")
else:
    print("You are not eligible to vote.")7. a. Print numbers from 1 to 10 using a for loop.
# Print numbers from 1 to 10 using a for loop
for i in range(1, 11):
    print(i)
b. Print the multiplication table of a number entered by the user.
# Multiplication table of a number
n = int(input("Enter a number: "))
for i in range(1, 11):
    print(n, "x", i, "=", n * i)c. Use a while loop to print numbers from 10 to 1.
# Print numbers from 10 to 1 using while loop
x = 10
while x >= 1:
    print(x)
    x -= 18. a. Create a list of five favorite fruits and print the second fruit.
# List example
fruits = ["Apple", "Banana", "Mango", "Grapes", "Orange"]
print("Second fruit:", fruits[1])b. Create a tuple with three numbers and print their sum.
# Tuple example
numbers = (10, 20, 30)
print("Sum of tuple numbers:", sum(numbers))9. a. Create a dictionary with three student names as keys and their ages as values.
students = {"Laiba": 14, "Tanzeel": 15, "Shahla": 13}
print("Age of Tanzeel:", students["Tanzeel"])b. Retrieve and print the age of a student from the dictionary.
students = {"Laiba": 14, "Tanzeel": 15, "Shahla": 13}
print("Age of Tanzeel:", students["Tanzeel"])10. a. Write a function to find the sum of two numbers.
# Function to find sum of two numbers
def add(a, b):
    return a + b
print("Sum:", add(5, 7))b. Write a function to find the sum of two numbers.
# Function to print a greeting message
def greet(name):
    print("Hello,", name + "!")
greet("Laiba")Quiz:
Coming Soon…
Supplementary Materials:
Provide downloadable materials for learners to review:
- – PDF Guide: “Coming Soon”
- – Cheat Sheet: “Coming Soon”
- – Video Source: “JNG ACADEMY“
- – Articles: “Blog Page“
