Self-Learning Python: Lesson 1 – Introduction to Python

Hello, welcome to your self-learning journey in Python!

Today, we will take the first step together. The goal of this lesson is to give you a preliminary understanding of programming and successfully run your first Python program. Don’t worry, this process is both simple and fun.

Course Objectives: Understand the basic concepts of programming, set up the Python environment, and successfully run your first line of code.

Core Content:

What is programming? Why choose Python?

Install Python and VS Code.

Use the print() function to output “Hello, World!”.

Learn how to add code comments.

1. Programming Worldview

What is programming?

In simple terms, programming is telling a computer to perform specific tasks using a language it can understand. The computers, mobile apps, and even smart appliances we use daily are powered by countless lines of code running behind the scenes.

You can think of programming as giving instructions to a very smart “robot”. As long as your instructions are clear and accurate enough, it can help you accomplish anything.

Why Choose Python?

Among many programming languages, we choose Python for several reasons:

  • Easy to Learn: Python’s syntax is very concise, almost like reading English sentences. This greatly lowers the entry barrier.

  • Powerful: Python has a wide range of applications, including web development, data analysis, artificial intelligence, automation scripts, and more.

  • Active Community: When you encounter problems, it’s easy to find abundant tutorials and community support online.

2. Environment Setup

Before we start writing code, we need to prepare our tools. Just like an artist needs brushes and a canvas, we need a Python interpreter to run the code and a code editor to write the code.

Installing Python

First, you need to download and install the Python interpreter from the official Python website.

  1. Visit https://www.python.org/downloads/.

  2. Download the latest version suitable for your operating system (Windows or Mac).

  3. Note: When installing on Windows, be sure to check the “Add Python to PATH” option. This allows you to run Python from any location, which is very convenient.

Installing VS Code

VS Code (Visual Studio Code) is a powerful, lightweight, free code editor that is very popular among developers.

  1. Visit https://code.visualstudio.com/ and download it.

  2. After installation, open VS Code. In the left extension panel, search for and install the “Python” extension, which will enhance VS Code’s support for Python development.

3. Hello, World!

Now that we have our tools ready, let’s write our first line of code!

  1. Create a new file in VS Code and name it <span>hello.py</span>. The <span>.py</span> extension indicates that this is a Python file.

  2. Type the following code in the file:

print("Hello, World!")
  1. Save the file.

  2. In the top menu bar of VS Code, find “Terminal” and select “New Terminal”.

  3. In the terminal, type <span>python hello.py</span> and press Enter.

If everything goes smoothly, you will see the output in the terminal:

Hello, World!

Congratulations! You have successfully run your first Python program!

The <span>print()</span> function is a built-in function in Python that outputs the content within the parentheses to the screen.

4. Code Comments

In programming, comments are explanatory text written for humans that is not executed by the Python interpreter. Developing the habit of writing comments is very important as it makes your code easier to understand and facilitates future modifications by yourself or others.

In Python, we use the <span>#</span> symbol to create single-line comments.

# This is a comment explaining the following code's function
print("Hello, Python!")  # You can also add comments at the end of a code line

Homework

Use the <span>print()</span> function to write a multi-line self-introduction. You can include your name, hobbies, or anything else you want to share.

If you encounter any issues during the environment setup or code writing process, feel free to ask questions.

Are you ready for the next lesson?

Leave a Comment