Course Outline (Part 2)

Before you can start writing and running Python code, you need to ensure Python is installed on your computer and set up a development environment. This guide will walk you through the process step-by-step.


1. Install Python

Many PCs and Macs will have python already installed. To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe):

C:\Users\Your Name>python --version

To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type:

python3 --version

If you find that you do not have Python installed on your computer, you can download it for free from the official Python website: https://www.python.org/downloads/

Note: During installation on Windows, make sure to check the box that says “Add Python to PATH”. This is crucial for running Python from the command prompt.


2. Set up Environment (VS Code, PyCharm, IDLE)

To write Python code, you need an Integrated Development Environment (IDE) or a code editor.

Python IDLE

When you install Python, it comes with a basic IDE called IDLE (Integrated Development and Learning Environment). It is a great starting point for beginners to test small snippets of code interactively.

Visual Studio Code (VS Code)

VS Code is a free, highly popular, and versatile code editor by Microsoft.

  1. Download and install VS Code from code.visualstudio.com.
  2. Open VS Code and go to the Extensions view (Ctrl+Shift+X).
  3. Search for “Python” and install the official Python extension by Microsoft. This will provide syntax highlighting, intellisense, and debugging capabilities.

PyCharm

PyCharm is a powerful IDE specifically designed for Python by JetBrains. It comes in a free Community edition and a paid Professional edition. It is excellent for larger projects and professional development.


3. Write first Python script

Let’s write our very first Python program. The traditional first program in any programming language is “Hello, World!”.

  1. Open your code editor (e.g., VS Code).
  2. Create a new file and save it as helloworld.py. The .py extension is essential, as it tells the editor and the operating system that this is a Python file.
  3. Write the following code in the file:
print("Hello, World!")

The print() function is a built-in Python function that outputs text to the screen.


4. Run Python from command line

Once you have written your script, you need to execute it.

  1. Open your command line interface (Command Prompt on Windows, Terminal on Mac/Linux).
  2. Navigate to the directory where you saved your helloworld.py file using the cd command. For example:
    cd Desktop/my_python_projects
  3. Run the script by typing python followed by the filename:
python helloworld.py

(Note: On some systems, particularly Mac and Linux, you might need to use python3 helloworld.py)

Output:

Hello, World!

Congratulations! You have successfully written and executed your first Python script. You are now ready to dive deeper into the syntax and features of the language.

Discussion

Loading comments...