Python Basics for AI (with Real-Life Examples)
1. Why Python for AI?
- Python is simple and easy to read (like English).
- It has many libraries for AI and Machine Learning (TensorFlow, PyTorch, scikit-learn).
- Big community support.
Examples:
1. Self-driving cars use Python to detect people, traffic lights, and objects.
2. Chatbots (like ChatGPT) use Python to understand and answer your questions.
2. Features of Python
- Simple & Easy: Looks like normal English.
- Free & Open-source: Anyone can use it.
- Portable: Works on Windows, Mac, Linux.
- Large Libraries: For math, AI, data, web, etc.
- Interpreted: Runs directly, no compile step.
Examples:
1. Instagram uses Python for its backend (server code).
2. Scientists use Python for analyzing satellite images in space research.
3. Installing Python
- Visit python.org
- Download the latest version.
- Install like normal software (Next → Next → Finish).
Examples:
1. Just like you install games on your PC, you can install Python.
2. Teachers can install Python on school computers to teach coding.
4. Setting up PATH
- PATH tells the computer where Python is kept.
- Tick “Add Python to PATH” during install.
- Then you can run Python from anywhere.
Examples:
1. If PATH is set, you can run Python from any folder in Command Prompt.
2. If PATH is not set, it’s like your school bag is lost — you can’t find your books when needed.
5. Running Python
- Open Command Prompt (CMD).
- Type: python
- Now you can write and run commands.
Examples:
1. A student types print("Hello World") to check if Python works.
2. A shopkeeper can quickly calculate bills using Python commands.
6. Running Python Script from Command Line
- Save code in a file, e.g., hello.py
print("Hello, I am learning Python")
- Open CMD → go to folder.
- Run: python hello.py
Examples:
1. A student writes marks.py to calculate average marks and runs it.
2. A doctor writes bmi.py to check BMI (Body Mass Index) and runs it for patients.
7. Integrated Development Environment (IDE)
- IDE is a special notebook for coding.
- Helps to write, run, debug easily.
- Popular IDEs: IDLE, PyCharm, Jupyter Notebook, VS Code.
Examples:
1. A data scientist uses Jupyter Notebook to test AI models step by step.
2. A beginner uses IDLE (comes with Python) to practice small programs.