Introduction to Python

What is Python and why use it?

What is Python and Why Use It?

What is Python?

Python is a high-level, general-purpose programming language that is easy to read, write, and learn. It was created by Guido van Rossum and first released in 1991. Today, it’s one of the most popular programming languages in the world.

Key Features of Python:

  • Simple and Readable Syntax – Python code looks like plain English, making it beginner-friendly.
  • Interpreted Language – No need to compile code before running it.
  • Dynamically Typed – You don’t need to declare variable types.
  • Cross-Platform – Works on Windows, macOS, Linux, etc.
  • Large Standard Library – Comes with built-in modules for tasks like file handling, math, and web services.
  • Massive Community Support – Tons of tutorials, libraries, and forums.

Where is Python Used?

Python is super versatile and used in many fields:

  • Web Development (e.g., Django, Flask)
  • Data Science & Machine Learning (e.g., Pandas, NumPy, Scikit-learn)
  • Automation & Scripting (e.g., Selenium, PyAutoGUI)
  • Game Development (e.g., Pygame)
  • Cybersecurity & Ethical Hacking
  • Mobile & Desktop Apps
  • IoT & Robotics
  • Education (Many schools teach Python first!)

Why Use Python?

  • Fast to learn, fast to write
  • Huge ecosystem of libraries
  • Scalable and powerful enough for big companies (used by Google, Netflix, Instagram, NASA)
  • Great for prototyping and automation
  • Supportive and active community

Setting up Python and IDEs (VSCode, Jupyter, etc.)

1. Install Python

Step 1: Download Python

  • Go to python.org
  • Download the latest stable version (recommended: Python 3.10+)

Step 2: Install Python

  • Windows: Check the box that says “Add Python to PATH” during installation
  • macOS/Linux: Use the installer or a package manager like brew or apt

Step 3: Verify Installation Open your terminal or command prompt and type:

python –version

Or

python3 –version

2. Choose an IDE or Code Editor

You can write Python code in many editors. Here are two great ones to start with:

VSCode (Visual Studio Code) – Recommended

Why use it?

  • Lightweight and fast
  • Tons of extensions
  • Great Python support

Steps to Set Up:

  • Download from code.visualstudio.com
  • Install the Python extension (search for “Python” in Extensions panel)
  • Create a new .py file and start coding!

Bonus Tips:

  • Use the integrated terminal (Ctrl + ~)
  • Use the debugger for step-by-step execution
  • Jupyter Notebook – Great for Data Science / Learning

Why use it?

  • Interactive cells (great for testing and data exploration)
  • Mix code with notes/markdown
  • Popular in data science and machine learning

How to Install: Option 1 – Using pip:

pip install notebook

Then run:

jupyter notebook

Option 2 – Install Anaconda (recommended for data science):

  • Download from anaconda.com
  • Includes Python, Jupyter, and many scientific libraries


Optional: Set Up a Virtual Environment

This helps isolate your project’s dependencies.

# Create a virtual environment
python -m venv venv

# Activate it
# Windows
venv\Scripts\activate

# macOS/Linux
source venv/bin/activate

Then install packages locally using:

pip install package-name

Running your first Python script

Step 1: Create a Python File

1. Open your IDE or code editor
(e.g., VSCode, Sublime Text, or even Notepad)

2. Create a new file and name it something like:

hello.py

3. Write your first Python code:

print(“Hello, world!”)

Step 2: Run the Script

There are several ways to run your script depending on the tool you’re using:

Option 1: Run in the Terminal / Command Prompt

1. Open terminal (or command prompt)

2. Navigate to the folder where your hello.py file is saved using cd:

cd path/to/your/folder

3. Run the script:

python hello.py

or (on some systems):

python3 hello.py

Output:

Hello, world!

Option 2: Run in VSCode

1. Open the hello.py file in VSCode.

2. Make sure the Python extension is installed.

3. Click the Run button in the top right, or right-click the code and select:

Run Python File in Terminal

VSCode will open a terminal and run the script.

Option 3: Run in Jupyter Notebook (Optional)

1. Launch a Jupyter Notebook:

jupyter notebook

2. Create a new Python notebook.

3. In the first cell, type:

print(“Hello, world!”)

4. Click Run

What Just Happened?

  • You created a .py file — this is a script written in Python.
  • The print() function outputs text to the screen.
  • Python reads your file line-by-line and runs it top to bottom.

Troubleshooting Tips:

  • Command not found?
    → Make sure Python is added to your system PATH
  • Permission error or syntax error?
    → Double-check your code for typos and indentation

Python REPL and basic syntax

What is the Python REPL?

REPL stands for:

Read → Eval → Print → Loop

It’s an interactive Python environment where you can write and run code line-by-line. Super useful for quick testing, experimenting, and learning!

How to Open the REPL

1. Open your Terminal (macOS/Linux) or Command Prompt (Windows)

2. Type:

python

or:

python3

You’ll see something like:

Python 3.10.7 (default, Aug 22 2022, 20:19:32)
>>>

The >>> prompt means you’re in the Python REPL and ready to start coding interactively.


Try These Commands in the REPL

>>> print(“Hello, REPL!”)
Hello, REPL!

>>> 5 + 3
8

>>> name = “Alice”
>>> name
‘Alice’

>>> len(name)
5

Basic Python Syntax Overview

1. Variables

name = “Python”
age = 30
is_active = True

  • No need to declare types
  • Use snake-case for naming

2. Indentation

Python uses indentation (spaces/tabs) to define blocks of code (instead of curly braces {}).

if age > 18:
print(“You’re an adult”)

Important: 4 spaces is standard indentation in Python

3. Comments

# This is a comment

  • Use # for single-line comments

  • Use triple quotes “”” for multi-line comments (unofficially)

4. Data Types & Examples

# Strings
name = “Bob”

# Integers
age = 25

# Floats
pi = 3.14

# Boolean
is_happy = True

# Lists
fruits = [“apple”, “banana”, “cherry”]

5. Basic Input & Output

# Output
print(“Hello, world!”)

# Input
name = input(“What is your name? “)
print(“Nice to meet you, ” + name)

6. Math Operators

Operator Meaning Example
+ Add 3 + 2
Subtract 5 – 1
* Multiply 4 * 2
/ Divide 6 / 3
// Floor Divide 7 // 2
% Modulus 8 % 3
** Power 2 ** 3

Pro Tip:

Use REPL like a calculator or sandbox. It’s perfect for learning and experimenting.

Leave a Comment