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

What’s in a Name? The Many Titles of a Software QA Engineer

Picture this: You've been testing software for  over a decade , breaking things, filing bug reports, and perfecting your  "Are you sure you deployed the right build?"  face. Then, one day, you meet another tester at a conference who introduces themselves as a  "Software Development Engineer in Test (SDET)." "Cool," you think. "Must be a fancy new role." But as they describe their work, your eye twitches. They do exactly what you do. Congratulations! You just discovered that your job has at least  a dozen other names , and depending on the company, you could've been called something way cooler—like  Automation Ninja, AI Test Engineer, or Bug Whisperer. So, to make sure no QA engineer gets  stuck in a title silo forever , here's a breakdown of  serious, AI-driven, and downright hilarious QA job titles  that exist in the wild. The Classic QA Titles: The OGs of Testing These are the traditional roles that have stood the test of time. If y...

Test Case Prioritization with AI: Because Who Has Time to Test Everything?

Let's be real. Running all the tests, every time, sounds like a great idea… until you realize your test suite takes longer than the Lord of the Rings Extended Trilogy. Enter AI-based test case prioritization. It's like your test suite got a personal assistant who whispers, "Psst, you might wanna run these tests first. The rest? Meh, later." 🧠 What's the Deal? AI scans your codebase and thinks, "Okay, what just changed? What's risky? What part of the app do users abuse the most?" Then it ranks test cases like it's organizing a party guest list: VIPs (Run these first) : High-risk, recently impacted, or high-traffic areas. Maybe Later (Run if you have time) : Tests that haven't changed in years or cover rarely used features (looking at you, "Export to XML" button). Back of the Line (Run before retirement) : That one test no one knows what it does but no one dares delete. 🧰 Tools That Can Do This M...

AI Visual Regression Testing: Because Your UI Shouldn’t Ghost You Overnight

Imagine spending weeks perfecting your app's UI.  The buttons are sleek, the layout's clean, and everything looks like it could win a design award. You go to bed feeling like a coding Picasso. Then… you wake up. Your buttons are misaligned. Your logo is somewhere in Ohio. And that "Sign Up" button? It's decided to explore a life of solitude. Welcome to the horror movie called Visual Regression,  where your UI goes rogue and doesn't text back. Enter AI: Your Pixel-Picking Sidekick Visual regression testing with AI compares snapshots of your app's UI over time, automatically detecting unintended visual changes like: A rogue font size tweak Padding that got a little too cozy Missing elements that got Thanos-snapped But instead of you manually comparing screenshots like a paranoid ex stalking your design system, AI handles it with laser focus and zero drama. How It Works (Without Making You Cry) Take a baseline scree...