Skip to main content

Quick 10-Minute Introduction to Python on macOS

Python is a versatile and beginner-friendly programming language, making it a great choice for macOS users. This guide will help you get started with Python in just 10 minutes.


Step 1: Check Python Installation

  1. Open Terminal (search for "Terminal" in Spotlight or find it in Applications > Utilities).

  2. Check if Python is installed by typing:

    python3 --version
    • If Python is installed, you’ll see a version number like Python 3.x.x.

    • If not, download Python or install it via Homebrew:

      brew install python

Step 2: Write Your First Python Script

  1. Create a new file for your script by typing:

    nano hello.py
  2. In the editor, type the following code:

    print("Hello, World!")
  3. Save and exit:

    • Press Ctrl + X, then Y, and hit Enter.

  4. Run your script:

    python3 hello.py

    You should see this output:

    Hello, World!

Step 3: Use Python Interactively

  1. Open the Python interactive shell:

    python3
  2. You’ll see a prompt like this:

    >>>
  3. Try typing Python commands directly:

    print("Welcome to Python!")

    Press Enter to see the output:

    Welcome to Python!
  4. Exit the shell by typing:

    exit()

Step 4: Explore Python Basics

Experiment with Python basics by running commands in the interactive shell or writing scripts:

Variables:

name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")

Loops:

for i in range(5):
    print(f"Number: {i}")

Functions:

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))

Lists:

fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(f"I like {fruit}")

Step 5: Use Python Modules

Python includes powerful built-in modules. Try these examples:

Math Module:

import math
print(math.sqrt(16))

Datetime Module:

from datetime import datetime
print(datetime.now())

Step 6: Install Python Packages

Use pip to install additional libraries.

  1. Install the requests library:

    pip3 install requests
  2. Write a script to fetch data from a website:

    import requests
    response = requests.get("https://api.github.com")
    print(response.json())

Step 7: Virtual Environment (Optional)

Set up an isolated Python environment for your projects:

  1. Create a virtual environment:

    python3 -m venv myenv
  2. Activate the environment:

    source myenv/bin/activate
  3. Install Python packages within the virtual environment.

  4. When done, deactivate the environment:

    deactivate

Step 8: Use a Code Editor

For a better coding experience, use a code editor like Visual Studio Code:

  1. Install VS Code.

  2. Add the Python extension:

    • Open VS Code.

    • Go to Extensions (Cmd + Shift + X).

    • Search for "Python" and install it.


Summary

  1. Write Python scripts using nano or a text editor.

  2. Run scripts with python3 <script_name.py>.

  3. Experiment with basic Python commands in the interactive shell.

  4. Install additional libraries using pip3.

  5. Use a code editor like VS Code for enhanced productivity.

With this quick introduction, you’re ready to start exploring Python on your Mac. Happy coding!

Comments

Popular posts from this blog

Building My Own AI Workout Chatbot: Because Who Needs a Personal Trainer Anyway?

The idea for this project started with a simple question: How can I create a personal workout AI that won't judge me for skipping leg day? I wanted something that could recommend workouts based on my mood, the time of day, the season, and even the weather in my region. This wasn't just about fitness—it was an opportunity to explore AI, practice web app engineering, and keep myself entertained while avoiding real exercise. Technologies and Tools Used To bring this chatbot to life, I used a combination of modern technologies and services (no, not magic, though it sometimes felt that way): Frontend: HTML, CSS, and JavaScript for the user interface and chatbot interaction (because making it look cool is half the battle). Backend: Python (Flask) to handle requests and AI-powered workout recommendations (it's like a fitness guru, minus the six-pack). Weather API: Integrated a real-world weather API to tailor recommendations based on live conditions (because nobody...

AI Wrote My Code, I Skipped Testing… Guess What Happened?

AI is a fantastic tool for coding—until it isn't. It promises to save time, automate tasks, and help developers move faster. But if you trust it  too much , you might just end up doing extra work instead of less. How do I know? Because the other day, I did exactly that. The Day AI Made Me File My Own Bug I was working on a personal project, feeling pretty good about my progress, when I asked AI to generate some code. It looked solid—clean, well-structured, and exactly what I needed. So, in a moment of blind optimism, I deployed it  without testing locally first. You can probably guess what happened next. Five minutes later, I was filing my own bug report, debugging like a madman, and fixing issues on a separate branch. After some trial and error (and a few choice words), I finally did what I should have done in the first place:  tested the code locally first.  Only after confirming it actually worked did I roll out the fix. Sound familiar? If you've ever used AI-gene...

Smart Automation: The Art of Being Lazy (Efficiently)

They say automation saves time, but have you ever spent three days fixing a broken test that was supposed to save you five minutes? That's like buying a self-cleaning litter box and still having to scoop because the cat refuses to use it. Automation in software testing is like ordering takeout instead of cooking—you do it to save time, but if you overdo it, you'll end up with a fridge full of soggy leftovers. Many teams think the goal is to automate everything, but that's like trying to train a Roomba to babysit your kids—ambitious, but doomed to fail. Instead, let's talk about smart automation, where we focus on high-value tests that provide fast, reliable feedback, like a well-trained barista who gets your coffee order right every single time. Why Automating Everything Will Drive You (and Your Team) Insane The dream of automating everything is great until reality slaps you in the face. Here's why it's a terrible idea: Maintenance Overhead: The more ...