We already have a basic understanding of Python, but let's not rush into learning just yet. First, we need to do some necessary preparation.
🎉 💯 This tutorial is applicable to python3.8+
.
What knowledge do you need?
This book assumes that you have no computer science background, such as computer systems, computer architecture, data structures, etc. While these topics are important, they are not something we need to consider at this stage. They will be of great help to you as you advance further. You should be familiar with operating a computer, including:
- Familiarity with software download and installation.
- Familiarity with using the command-line interface (Windows) or terminal (Mac, Linux).
- Basic operation of an IDE software.
Now let's use the knowledge mentioned above to run our first Python program.
Running the first Python program
To learn and develop Python programs on your computer, you need to do some preparation. Here, we will demonstrate the first Python program using the "Hello World" program as an example.
Environment Setup
(1) First, download and install the latest version of Python. You can download the corresponding installation program from the Python official website https://www.python.org/downloads/.
(2) After installation, open the command-line interface (Windows) or terminal (Mac, Linux) and enter the
python
command. If you see similar output as below, it means Python has been successfully installed:bashPython 3.9.4 (default, Apr 5 2021, 01:37:28) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
Python 3.9.4 (default, Apr 5 2021, 01:37:28) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
(3) Next, we can install an Integrated Development Environment (IDE) for writing Python code, such as PyCharm, VS Code, etc. Taking PyCharm as an example (choose the free Community edition), you can download the corresponding installation program from the official website https://www.jetbrains.com/pycharm/download/ and follow the instructions to install it.
Writing Python Code
(1) Open PyCharm and create a new Python project. Select "File" > "New Project" from the menu bar, then follow the prompts to set the project name and path.
(2) Create a new Python file. Right-click in the project panel, select "New" > "Python File," and enter the file name.
(3) Write your code in the Python file, for example:
python# This is a Python program that prints "Hello World!" print("Hello World!")
# This is a Python program that prints "Hello World!" print("Hello World!")
Running the Program
(1) Click "Run" in the PyCharm editor or press the shortcut key "Shift + F10" to run the program.
(2) If everything goes well, the program will output the text "Hello World!" in the console.
By following these steps, beginners can quickly write and run their first Python program. Of course, this is just a simple introductory example. Python has many other features and applications. We hope it sparks learners' interest and curiosity to continue exploring and learning more about Python's knowledge and applications.