Getting started with Python(3)

Section 3 Hello world
Hello everyone, in this lesson we will learn together: Where to write and how to run Python code?

**Recap: **

In the last lesson, we have downloaded and installed Python on our computer.

And in the Windows start menu of the computer, I have seen the installed Python software, and we can use it immediately.

1、 A little test___ My first line of Python code

Hello World!

——Yes, that's it! The first line of code written by programmers all over the world.

2、 There are two scenarios where you can write and run Python code

One is in the DOS window of Windows

The other is the integrated development environment that comes with Python: IDLE

Below, we respectively write and run our first line of Python code in the above two environments.

‍PS: Please note that no matter in which scene, they have two ways to use them.

Scenario 1: Write and run Python code in DOS window

1、 Interactive mode: write and run immediately

Next, we can write our first line of Python code here.

According to Python's syntax, if we want to display Hello World! on the screen,

Then, you can use its screen printing function print(),

The method of use is to put the content to be displayed in parentheses and use quotation marks.

Namely: print("Hello World!").

After the code is written, just press the Enter key,

Hello World!

It is displayed after >>> on the next line.

As shown below:

**2、 File operation mode: **Run the compiled Python file world.py

Suppose there is a StudyPython folder in the D drive of the computer,

There is a Python file world.py under it, which has already been written (to be mentioned later),

The content of the file is a line of code:

print(“Hello World!”),

Then, it can also be displayed by file running mode:

“Hello World!”。

As shown below:

Scenario 2: Writing and running Python code in IDLE

1、 Interactive mode: run Python program directly in Python IDLE window

We are behind the ">>>" prompt of the Python Shell,

Direct input: print("Hello World!"),

After the enter key,

It immediately displays: "Hello World!".

As shown below:

**(2) File operation mode: ** In the Python IDLE window, run the Python program.

**Step 1: **Click the File menu to open a Python file editing window

Remarks: The demo code of this course is saved in the folder D:\StudyPython

**Step 2: **In the File editing window, press F5 to directly run the current program file, and the running result will be displayed in the python shell. As shown below.

3、 Special introduction to Python IDLE

As you have seen, we can write and run Python code in at least two scenarios. However, it is obvious that we cannot always write and run the program code in the DOS window, which is too inconvenient. The correct approach is to choose a suitable integrated development environment (IDE) to write our program code, then, here I suggest you, as an introductory programming to Python, using IDLE that comes with Python will be a good choice.

IDLE is an integrated development environment that comes with the Python software package, and beginners can use it to easily create, run, test and debug Python programs.

After starting IDLE, we can see its Python Shell, through which we can execute Python commands inside IDLE. In addition, IDLE also comes with a program file editor, an interactive interpreter for executing Python statements, and a debugger for debugging Python scripts.

IDLE provides developers with many useful features, such as automatic indentation, syntax highlighting, automatic word completion, and command history. In the future, with the help of these functions, we can effectively improve the efficiency of our code writing.

Don’t worry about whether you will use this software or not. In the next course, we will introduce the functions of IDLE in detail, and use Python IDLE to write and run our code more and more. I believe you will be familiar with and adapt to it soon. it. In the future, we will also introduce you to more powerful integrated development tools, making our programming easier and simpler!

**4、 How to exit from Python? **

Well, if the programming work is over, how to quit?

(1) Exit from the python environment of the DOS window: press [ctrl + z + enter] key combination

(2) Exit from IDLE (python shell): press [ctrl + Q] key combination

summary

In this lesson, we learned how to write a simple python program: Hello World!

1、 There are two operating environments for writing and running python code, DOS and Python Shell.

2、 It is recommended to insist on writing and running python code in the IDLE integrated development environment that comes with Python.

Recommended Posts

Getting started with Python(9)
Getting started with Python(8)
Getting started with Python(4)
Getting started with Python (2)
Getting started with python-1
Getting started with Python(14)
Getting started with Python(17)
Getting started with Python(15)
Getting started with Python(10)
Getting started with Python(11)
Getting started with Python(6)
Getting started with Python(3)
Getting started with Python(12)
Getting started with Python(5)
Getting started with Python (18+)
Getting started with Python(13)
Getting started with Python(16)
Getting started with Numpy in Python
Getting started with Ubuntu
Getting Started with Python-4: Classes and Objects
Getting started with python-2: functions and dictionaries
04. Conditional Statements for Getting Started with Python
Getting started python learning steps
How to get started quickly with Python
python requests.get with header
Web Scraping with Python
Implementing student management system with python
Played with stocks and learned Python
Gray-level co-occurrence matrix (with python code)
Speed up Python code with Cython
How to make a globe with Python
Automatically generate data analysis report with Python
Create dynamic color QR code with Python
Python | Quickly test your Python code with Hypothesis
How to process excel table with python