Auto Code Wizard Logo
  • Home
  • Services
  • Honey Control App
  • How it works
  • About
    • About Us
    • Podcast Partners
    • Contact
    • FAQ
    • Terms
  • Blog
  • Code Types
    • All
    • Bash
    • PHP
    • Python
    • PowerShell
    • JavaScript
  • Code Wizard Login
  1. Home
  2. code-wizard
  3. courses-home
  4. Python - Getting Started

Python Getting Started

This page will hopefully give you all that you need to get your started with Python.

Python Files Overview

Python is a scripting language where you write code in files with the .py extension, such as myfirstfile.py. File names can’t have spaces, but underscores (_) and dashes (-) are allowed, so my_first_file.py or my-first-file.py are perfectly fine.

Using IDLE (Integrated Development and Learning Environment)

IDLE is Python’s built-in editor, designed to help beginners start writing and running Python code quickly.

Download and install it from https://www.python.org/downloads/

1. Open IDLE

After installing Python, IDLE is usually available in your applications or start menu as "IDLE (Python x.x)". Open it to see two windows: the Python Shell (where you can type and immediately run Python code) and the Editor (where you can save and run code files).

Python idle start menu

2. Create a New Python File

In the IDLE menu, go to File → New File. A new editor window will open. Type some Python code into the editor, such as:

print("Hello from IDLE!")

Python idle new file

3. Save Your File

Go to File → Save As… and name your file, for example, my_first_file.py. Choose a location you can easily access, like your Desktop or a specific project folder.

Python my first file

4. Run Your Python Code

In the editor window, go to Run → Run Module (or press F5 on your keyboard). The output will appear in the Python Shell window, displaying:

Hello from IDLE!

Python idle run module

Python idle run module result

IDLE makes it easy to test small scripts quickly, but for larger projects, many developers use a more advanced editor like VS Code.

Using Visual Studio Code (VS Code)

VS Code is a powerful, free editor that’s popular for all kinds of programming, including Python. Here’s how to use it for Python scripting.

Download from https://code.visualstudio.com/download

1. Install VS Code and the Python Extension

If you haven’t already, download and install VS Code. Open VS Code and go to the Extensions view (by clicking the square icon on the sidebar or pressing Ctrl+Shift+X). Search for Python and install the official Python extension by Microsoft. This will enable Python-specific features.

Python VSCode extensions - highlighted in green

2. Create a New Python File

Open a new file by going to File → New File. Save it as my_first_vscode_file.py by going to File → Save As… and choosing a location.

3. Write Some Python Code

In your new file, add Python code like this:

print("Hello from VS Code!")

4. Run Your Python Code

Make sure the Python interpreter is set up in VS Code (the Python extension should automatically detect it). There are several ways to run your code:

  • Click the Run Button: You’ll see a small "Run" button at the top-right corner of your editor. Click it, and the code will run in the Terminal at the bottom.
  • Use the Terminal: Open the terminal by going to View → Terminal, then type:
python my_first_vscode_file.py

Your output should display in the Terminal:

Hello from VS Code!

Python VSCode my first vscode file

5. (Optional) Use a Virtual Environment in VS Code

For projects that involve installing additional packages, you might want to set up a virtual environment.

python -m venv myenv

Activate the environment:

  • Windows: myenv\Scripts\activate
  • Mac/Linux: source myenv/bin/activate

Once activated, VS Code will use this environment for running your Python code. You can deactivate it by typing deactivate in the terminal.

By following these steps, you’ll be able to write, save, and test your Python code easily using either IDLE or VS Code, giving you flexibility across different tools!

Logo
AutoCodeWizard - AI-Powered Coding Assistant | Product Hunt [email protected]

autocodewizard.com