Pycharm 简明教程

Pycharm - Understanding Basics

本章将讨论 PyCharm 的基础知识,并让您在 PyCharm 编辑器中轻松开始工作。

This chapter will discuss the basics of PyCharm and make you feel comfortable to begin working in PyCharm editor.

当您首次启动 PyCharm 时,您可以看到一个欢迎屏幕,包含到 IDE 的入口点,例如 −

When you launch PyCharm for the first time, you can see a welcome screen with entry points to IDE such as −

  1. Creating or opening the project

  2. Checking out the project from version control

  3. Viewing the documentation

  4. Configuring the IDE

pycharm basics

回想一下,在上一章中,我们创建了一个名为 demo1 的项目,在整个本教程中,我们将参考同一项目。现在,我们将开始在同一项目中创建新文件,以了解 PyCharm Editor 的基础知识。

Recall that in the last chapter, we created a project named demo1 and we will be referring to the same project throughout this tutorial. Now we will start creating new files in the same project to understand the basics of PyCharm Editor.

demo project

上方的快照描述了 demo1 的项目概述以及创建新文件选项。让我们创建一个名为 main.py 的新文件。

The above snapshot describes the project overview of demo1 and the options to create a new file. Let us create a new file called main.py.

包含在 main.py 中的代码如下 −

The code included in main.py is as follows −

y = 3

def print_stuff():
   print ("Calling print_stuff")
   print (y)
   z = 4
   print (z)
   print("exiting print_stuff")

print_stuff() # we call print_stuff and the program execution goes to (***)
print(y) # works fine
print (z) # NameError!!!

使用 PyCharm Editor 在 main.py 中创建的代码如下所示 −

The code created in the file main.py using PyCharm Editor is displayed as shown below −

main project

可以在 IDE 环境中运行此代码。下面讨论了运行程序的基本演示 −

This code can be run within IDE environment. The basic demonstration of running a program is discussed below −

run main

请注意,我们已在指定代码中包含一些错误,以便控制台可以执行代码并按预期的方式显示输出。

Note that we have included some errors within the specified code such that console can execute the code and display output as the way it is intended to.

display output