Python Programming Textbook
📗 Module 1: Introduction to Python
🔍 What is Python?
Python is a powerful, easy-to-learn programming language used by beginners and professionals
worldwide. It is known for its clean syntax and versatility. Python can be used in various fields like:
• Web development
• Data analysis
• Artificial intelligence
• Automation
• Game development
✅ Key Features of Python:
• Simple and easy-to-understand syntax
• Free and open-source
• High-level and interpreted
• Portable across platforms (Windows, Mac, Linux)
• Huge library support (NumPy, Pandas, etc.)
📘 Why Learn Python?
• Python is beginner-friendly
• Used by big companies like Google, Netflix, and NASA
• High demand in the job market
• Great for both small scripts and large projects
📄 Installing Python
1. Go to the official website: [Link]
2. Download the latest version
3. Install Python and check "Add Python to PATH"
4. Open Terminal (Mac/Linux) or Command Prompt (Windows):
python --version
You should see something like:
1
Python 3.12.1
📈 Choosing an IDE (Editor)
You can write Python code using:
• IDLE (comes with Python)
• VS Code (lightweight and beginner-friendly)
• PyCharm (feature-rich for big projects)
• Jupyter Notebook (for data science and visualization)
⚙️ Your First Python Program
Open your code editor or terminal and type:
print("Hello, World!")
🔄 Output:
Hello, World!
This is the simplest Python program. The print() function is used to display output.
🌐 Real-Life Use Cases of Python
• Instagram backend (Django/Python)
• YouTube data analysis
• Netflix recommendation engine
• Chatbots and AI tools
• Robotics & IoT automation
🚲 Practice Exercises
1. Install Python and run it in your terminal
2. Write a program that prints your name
3. Write a program that prints today’s date
import datetime
print("Today is:", [Link]())
2
🎯 Mini Project: Basic Calculator
# Simple Calculator in Python
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Choose operation (+, -, *, /): ")
if operation == '+':
print("Result:", num1 + num2)
elif operation == '-':
print("Result:", num1 - num2)
elif operation == '*':
print("Result:", num1 * num2)
elif operation == '/':
print("Result:", num1 / num2)
else:
print("Invalid operation")
🎖️ Try it yourself:
• Modify the calculator to repeat until the user types "exit"
• Add support for modulus (%)
🔄 Summary Table
Concept Description
Python A beginner-friendly programming language
print() Function to display output
IDE Tool to write and run code
Input Takes user input via keyboard
✨ Pro Tips
• Use comments ( # ) to explain your code
• Save files with .py extension (e.g., [Link] )
• Practice consistently
📗 Module 2: Variables, Data Types & Type
Casting
3
📁 What are Variables?
Variables are names that store information (data) in a Python program. Think of them as labeled
containers.
name = "Alice"
age = 25
height = 5.4
In the above code:
• name stores a string
• age stores an integer
• height stores a float
📌 Rules for Naming Variables:
• Can contain letters, numbers, and underscores
• Cannot start with a number
• Are case-sensitive ( Name and name are different)
🔢 Python Data Types
Data Type Example Description
int 10 Integer numbers
float 10.5 Decimal numbers
str "Hello" Text/String data
bool True, False Boolean values (True/False)
🏛️ Type Casting (Conversion)
Python allows converting one data type to another:
x = 5 # int
y = float(x) # convert to float
z = str(x) # convert to string
Built-in Functions:
• int() → convert to integer
• float() → convert to float
• str() → convert to string
4
• bool() → convert to boolean
✏️ Taking User Input
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name)
Output Example:
Enter your name: Upendra
Enter your age: 22
Hello Upendra
🚲 Practice Exercises
1. Create variables for your name, age, and favorite food
2. Take two numbers as input and print their sum
3. Convert a string "123" to an integer
🎯 Mini Project: User Profile Card
name = input("Enter your name: ")
age = input("Enter your age: ")
city = input("Enter your city: ")
print("\n--- User Profile ---")
print("Name:", name)
print("Age:", age)
print("City:", city)
🔄 Summary Table
Concept Description
Variable A container to store data
Data Type Type of value stored in a variable
Type Casting Changing data from one type to another
input() Function to get user input
5
✨ Pro Tips
• Use meaningful variable names (e.g., age , not a )
• Convert input to correct data type ( int() , float() )
• Use type() to check the data type of a variable
Next Module: Operators & Expressions