Python Basics

Course by zooboole,

Last Updated on 2025-02-26 16:14:49

Python Development Routine

Before we start coding, let’s set up a proper development environment. Having the right tools will make it easier to write, test, and debug your Python programs.

1. Choosing Your Python Environment

There are multiple ways to write and run Python code. Below are the most common options:

1.1 Python Interactive Shell (REPL)

Python comes with a built-in interactive shell, also called the REPL (Read-Eval-Print Loop). It allows us to quickly run Python commands without saving them in a file.To open the it do this:

  • On Windows, open Command Prompt (cmd) and type:
python
  • On macOS/Linux, open the Terminal and type:
python3

You should see something similar to this:

Python 3.11.7 (main, Dec 7 2023, 09:07:50) [GCC 13.2.0 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

Now, you can type Python commands directly and see instant results!

>>> print("Hello, Python!")
**Hello, Python!**

To exit the shell, type exit() or press Ctrl + Z (Windows) or Ctrl + D (Mac/Linux) and hit Enter.

1.2 Writing Python Scripts (.py files)

While the interactive shell(REPL) is great for quick testing, you’ll mostly write Python programs in script files with the .py extension. And here the steps to Write and Run a Python Script:

  1. Open a text editor (Notepad, VS Code, PyCharm, or any editor of your choice or you are most comfortable with).

  2. Type your Python code. Example:

print("Welcome to Python!")
  1. Save the file with a .py extension, e.g., my_script.py.
  2. Open the Command Prompt/Terminal and navigate to the folder where your file is saved with cd.
  3. Run the script using:
python my_script.py

or (on macOS/Linux):

python3 my_script.py

Then Enter

  1. You should see the output printed on the screen!

1.3 Using an IDE or Code Editor

An Integrated Development Environment (IDE) makes Python development easier by providing features like syntax highlighting, auto-completion, debugging, and project management.

Here are some of the best options:

VS Code – Lightweight and powerful (Recommended for beginners).

PyCharm – A full-featured IDE, best for large projects.

Jupyter Notebook – Great for data science and quick experiments.

IDLE – Comes with Python by default, simple and easy to use.


Running Code in VS Code

  1. Install VS Code from https://code.visualstudio.com.
  2. Install the Python extension in VS Code.
  3. Open VS Code, create a new Python file (.py), and start coding.
  4. Click the Run button or press Ctrl + Shift + P, then type Run Python File in Terminal.

1.4 Online Python Interpreters (No Installation Needed!)

If you don’t want to install anything, you can use online Python compilers: