Starting my journey with Python has been exciting and also a bit overwhelming at the same time. Python is a popular, beginner-friendly programming language with a vast array of resources and a welcoming community.
To kick off my Python adventure, I turned to the "TechWorld with Nana" YouTube channel and the official Python documentation.
Let me walk you through how I set up my Python environment and wrote my very first script.
Setting Up the Python Environment
Step 1: Installing Python
First things first, we need to install Python on your computer. Here’s how to do it:
Visit the Official Python Website: Head over to python.org.
Download Python: Go to the downloads section and pick the latest stable version for your operating system (Windows, macOS, or Linux). Since I am using Windows, I will use that.
Run the Installer:
For Windows: Run the
.exe
file you downloaded. Make sure to check the box that says "Add Python to PATH" before you click "Install Now."For macOS and Linux: Follow the prompts in the installer. On Linux, you might need to use
sudo
for administrative permissions.
Step 2: Verifying the Installation
After the installation, let’s make sure everything is set up correctly. Open your terminal (Command Prompt on Windows, Terminal on macOS, or your preferred terminal on Linux) and type:
python --version
You should see the version number of Python you installed, confirming that Python is ready to go.
Step 3: Setting Up a Code Editor
While you can write Python code in any text editor, a dedicated code editor or an Integrated Development Environment (IDE) makes the process much smoother. Here are some popular choices:
Visual Studio Code (VS Code): A lightweight yet powerful code editor from Microsoft.
PyCharm: A feature-rich IDE tailored for Python development.
Sublime Text: A versatile text editor with a plethora of plugins.
For this guide, we’ll use VS Code.
Download and Install VS Code: Visit code.visualstudio.com and download the installer for your OS.
Install the Python Extension: Open VS Code, click on the Extensions icon on the Sidebar (or press
Ctrl+Shift+X
), and search for "Python." Install the extension by Microsoft.
Writing Your First Python Script
With everything set up, it’s time to write your first Python script. Let’s start with the classic "Hello, World!" example.
Step 1: Creating a Python File
Open VS Code.
Create a New File: Click on
File > New File
or use the shortcutCtrl+N
.Save the File: Save it with a
.py
extension (e.g.,hello_
world.py
). This tells VS Code that it’s a Python file.
Step 2: Writing the Script
In your new Python file, type this simple line of code:
print("Hello, World!")
This line uses the print()
function to display "Hello, World!" in the console.
Step 3: Running the Script
Now, let’s run your script:
Open the Integrated Terminal: In VS Code, go to
View > Terminal
or pressCtrl+`
(backtick).Navigate to the Script Directory: Use the
cd
command to move to the directory where you saved your script. For example:cd path/to/your/script
Run the Script: Type the following command and press Enter:
python hello_world.py
You should see the output:
Hello, World!
Here is an actual screenshot
And there you have it! You’ve successfully written and run your first Python script.
Next Steps
Now that you’ve got your Python environment set up and your first script under your belt, it’s time to explore more. Here’s what you can dive into next:
Learn Python Basics: Get familiar with variables, data types, and basic operators.
Understand Control Flow: Learn about conditionals (
if
,elif
,else
) and loops (for
,while
).Master Functions: See how to define and use functions to organize your code.
Explore Libraries and Frameworks: Start with Python’s built-in libraries and then check out popular ones like NumPy, Pandas, and Flask.
Using resources like the "TechWorld with Nana" YouTube channel and the official Python documentation, you’ll continue to build your Python skills and tackle exciting projects.
Other resources
Codecademy
Coursera
Programming With Mosh YouTube Channel
freeCodeCamp
DataCamp
...and so many others (please share in the comments)
Happy coding!