Programming LanguagesPythonTutorials

Get Started with Python

Welcome to this tutorial on getting started with Python using Visual Studio Code (VS Code)! In this guide, we’ll walk you through the installation process of Python, how to set it up in VS Code, and validate your installation. We’ll also explore some handy extensions that can enhance your Python development experience. Let’s dive in!

What is Visual Studio Code and Why is It Preferred?

 
Visual Studio Code is a free code editor developed by Microsoft. It’s lightweight, fast, and comes with a host of features that make coding in Python (and other languages) easier. Here are a few reasons why developers prefer it:

  • IntelliSense: You get smart completions based on variable types, function definitions, and imported modules.
  • Debugging: A powerful built-in debugger to test and troubleshoot your code.
  • Extensions: A rich marketplace full of extensions that can help enhance your development workflow.
  • Customizability: You can tailor your environment based on your needs.

How to Install Python

  1. Download Python:
    • Go to the official Python website: python.org.
    • Click on the download button appropriate for your operating system (Windows, Mac, or Linux).
  1. Run the Installer:
    • Open the downloaded installer.
      • Note! Durring installation please copy complete path where python is being installed we may need it later.
    • Important: Check the box that says “Add Python to PATH”.
    • Click on “Install Now”.

Validate Your Installation

  1. Open Command Prompt:
    • Press Win + R, type cmd, and hit Enter.
  2. Check Python Version:
    • In the command prompt, type:
    • python --version
    • If Python is installed correctly, you should see the version number.
  1. If Not Validated:
    • Restart Your PC: Sometimes, the changes might need a restart to take effect.
    • Check Again Before Moving Forward.

If Still Not Validated, Add Python to Windows PATH Manually

  1. Open Environment Variables:
    • Press Win + S to open the Search bar (or click the Start menu).
    • Type “Environment Variables” and select “Edit the system environment variables” from the search results.
    • In the System Properties window that appears, click the “Environment Variables” button near the bottom.
  2. Edit the Path Variable:
    • In the Environment Variables window, look for “Path” under System Variables and select it.
    • Click on “Edit”.
    • In the Edit Environment Variable window, click on “New” and add the path to your Python installation. Normally, it’s located at: C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python<version>\

 
3. Add Scripts Folder (Optional but Recommended):

  • It’s also helpful to add: C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python<version>\Scripts\

 
4. Click OK and close out of the settings windows.

5. Re-verify the Installation: Open Command Prompt again and check using:

python --version  

Setting Up Visual Studio Code

  1. Install VS Code:
    • Download from the official site: code.visualstudio.com.
    • Open the installer and follow the instructions. You can choose default options.
  1. Open VS Code:
    • After installation, launch Visual Studio Code.
  2. Install Python Extension:
    • Click on the Extensions icon (square icon on the sidebar).
    • Search for “Python” and select the one published by Microsoft.
    • Click Install.

Create and Run a Python Script

  1. Create a New Python File:
    • First open folder where u want to save your python file.
    • Click File -> New File.
    • Save it as hello.py.
  1. Write Your Python Code: print("Hello, World!") and run it.

 
3. Open the Terminal in VSCode:

  • If want manually run python file using command try it.
  • Click on Terminal -> New Terminal.
  • In the terminal, type: python hello.py

 
4. Test It:

  • You should see the output Hello, World! in the terminal!

Some Bonus Extensions for Python in VS Code

  1. Pylance: Offers better type checking and faster IntelliSense.
  2. Jupyter: For working with Jupyter Notebooks directly within VS Code.
  3. AutoPep8: Automatically formats your Python code to conform to the PEP 8 style guide.

Practice Tasks

Task 1: Modify the hello.py Program

  • Change the message in hello.py to something personal, e.g., print("Hello, [Your Name]!").
  • Run the file again and see the change in the output.

Engagement

 
You’re all set up to start coding! Try the tasks and share your answers in the comments to get appreciated! Happy coding!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button