Curso de Python para iniciantes #01 - Configurar o ambiente e Hello World

3 min read 3 months ago
Published on Aug 29, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through setting up your Python development environment and writing your first Python script. By the end of this guide, you will have a Python installation, a code editor set up, and a simple "Hello World" script running. This foundational knowledge is essential for anyone starting in programming with Python.

Step 1: Understand the Importance of Python

Before diving into installation, here are a few reasons to learn Python:

  • Popularity: Python is one of the most widely used programming languages, utilized by major companies like Google, Facebook, and Netflix.
  • Versatility: It can be used for various applications, including web development, data science, automation, and machine learning.
  • High Demand: There are numerous job opportunities, with competitive salaries in the tech industry.
  • Community Support: Being open-source, it has a vast community that continuously contributes to resources and libraries.

Step 2: Install Python

To get started with Python, follow these steps:

  1. Visit the Python Website: Go to python.org/downloads.
  2. Download Python: Choose the latest version of Python 3 (currently 3.9.0) suitable for your operating system (Windows, macOS, or Linux).
  3. Install Python:
    • For Windows and macOS, run the downloaded installer and follow the prompts.
    • For Linux, use your package manager to install Python if it’s not already installed.
  4. Verify Installation:
    • Open the Command Prompt (Windows: press Windows + R, type cmd).
    • Type python --version and press Enter. You should see the version number displayed.

Step 3: Install Visual Studio Code

A good Integrated Development Environment (IDE) makes programming easier. Follow these steps to install VS Code:

  1. Visit the VS Code Website: Go to code.visualstudio.com.
  2. Download VS Code: Choose the version compatible with your operating system.
  3. Install VS Code: Run the installer and follow the instructions.
  4. Create a New Project Folder:
    • Open VS Code.
    • Click on File, then Open Folder.
    • Create a new folder named CursoPython and a subfolder named HelloWorld for this course.

Step 4: Create Your First Python Script

Now that your environment is set up, you can write your first script.

  1. Create a New Python File:
    • In the HelloWorld folder, create a new file and name it helloworld.py.
  2. Write the Script:
    • Open helloworld.py and enter the following code:
    print("Hello World")
    
  3. Run the Script:
    • Use the debug button in VS Code to run your script.
    • You should see "Hello World" printed in the console.

Step 5: Modify the Script

To understand how the print function works:

  1. Change the Output:
    • Replace "Hello World" with your name:
    print("Your Name")
    
  2. Run the Script Again:
    • Execute the script to see your name displayed in the console.

Conclusion

You have successfully set up your Python environment, installed an IDE, and run your first Python script. This is just the beginning of your programming journey with Python. As you progress, consider exploring more complex projects and concepts. Keep practicing, and don't hesitate to reach out to the community for support as you learn. Happy coding!