Learn Python: Introduction and Setup
Python is a versatile programming language known for readability and a large ecosystem of libraries. It is used for web development, data analysis, automation, artificial intelligence, and many other applications. In this lesson, you will set up Python on your system and learn how to run Python code in Visual Studio Code (VS Code). This prepares you for all upcoming lessons in this course.
What will be covered
• Installing Python and verifying that it runs correctly.
• Differences between using the Python interpreter interactively and running scripts in VS Code.
• Creating and running a simple Python program (“Hello, World!”) to confirm your setup.
• Navigating essential features in VS Code that optimize your Python development workflow.
Why it’s important
Properly installing Python ensures you avoid technical glitches. By learning how to run scripts in VS Code, you set a solid foundation for more complex tasks. Python’s reach spans web development, scripting, and data science, so mastering the basics of your environment lets you follow these different paths without extra hassle.
Installing Python
1. Go to python.org/downloads and download the latest release for your operating system.
2. On Windows, check “Add Python to PATH” during installation. On Mac/Linux, follow the default or customized steps
as preferred.
3. After installation, open a terminal and run
python --version or python3 --version. You should see a version number output,
confirming that Python is recognized.
Using the Python Interpreter
When you type python in a terminal, it launches an interactive session called the REPL (Read-Eval-Print Loop). This is a quick way to test short snippets or explore Python’s functionality. Once you exit the REPL (often by typing exit()), you return to your normal terminal prompt.
Setting Up Visual Studio Code
1. Download and install VS Code from code.visualstudio.com.
2. Open VS Code and navigate to the Extensions tab. Search for “Python” by Microsoft and install it.
3. Open a folder where you plan to store your Python scripts. When VS Code prompts you to select a Python interpreter,
choose the one you installed. This ties your VS Code environment to the correct Python version on your machine.
Running a Simple Python Program in VS Code
Create a file named hello.py in your project folder. Enter this code:
print("Hello, World from VS Code!")
To run it, open a terminal inside VS Code (View > Terminal) and type: python hello.py, or use the “Run” button in the top-right corner of the VS Code interface.
Practice Exercises
- Open the Python interpreter by typing python in a terminal. Type print("I am practicing Python"), then type another line with a different print statement. Notice how each line displays immediately.
- Create a file named two_messages.py in VS Code. In it, print one sentence about yourself, then print another sentence about your favorite hobby. Run it from the terminal to see both lines.
- Make a file named shout.py that prints a short message in uppercase letters. Run it and confirm you see the exact text displayed in your terminal.
Summary
You have now installed Python, tested the interactive interpreter, and used VS Code to create and run a simple Python script. These steps establish a reliable workflow for future lessons. By practicing different print statements, you confirm that your environment is functioning and you can see immediate feedback. You are now set to progress into deeper Python concepts with a stable setup in place.