current position:Home>Chapter 1: introduction to Python programming-4 Hello World

Chapter 1: introduction to Python programming-4 Hello World

2022-01-30 05:36:22 Small horn

Python Hello World

The goal is

In this article , You will learn how to use Python Develop the first program “Hello, World!”.

Create a new Python project

First , Create a file called helloworld New folder for .

second , start-up VS Code and open helloworld Folder .

Third , Create a new file , Enter the following code and save the file :

 Copy code 

print() Is a built-in function , Used to display messages on the screen . In this case , It will display messages “Hello, Word!

What is a function

When you add two numbers , This is a function . When you multiply two numbers , It's also a function .

Each function accepts your input , Apply some rules , And return a result .

In the example above ,print() It's a function . It accepts a string and displays it on the screen .

Python There are many built-in functions , Such as print() function , So you can use them out of the box .

Besides ,Python Allows you to define functions , Later you will learn how to do this .

perform Python Hello World Program

To execute file , First, in the Windows or macOS or Linux Start the command prompt on .

then , Navigate to helloworld Folder .

then , Enter the following command to execute file :

 Copy code 

If everything goes well , You will see the following message on the screen :

 Copy code 

If you use VS Code, You can also start by VS Code Terminal in :

  • Enter menu “Terminal>New Terminal”
  • Or use keyboard shortcuts Ctrl+Shift+`.

Usually , Backquote key (`) Located on the keyboard Esc Under key .

Python IDLE

Python IDLE yes Python By default, the distribution comes with Python Integrated development environment (IDE).

Python IDLE Also known as interactive interpreter . It has many characteristics , Such as :

  • Use syntax highlighting for code editing
  • Smart indent
  • And autocomplete

In short ,Python IDLE Help you experiment quickly by trial and error Python.

Next, step by step, I'll show you how to start Python IDLE And use it to perform Python Code :

First , start-up Python IDLE Program :

8.jpg A new Python Shell The window will display as follows :

9.jpg Now? , You can use the cursor >>> After input Python Code , And press Enter Key to execute it .

for example , You can enter the code print('Hello, World!'), Then press Enter key , You'll see Hello, World! Immediately appear on the screen :



  • stay Windows or macOS or Linux Used in terminals on python Path to file .py Command to execute Path to file .py file .
  • Use print() Function displays a message on the screen .
  • Use Python IDLE Input Python Code and execute immediately .

copyright notice
author[Small horn],Please bring the original link to reprint, thank you.

Random recommended