Python Basics | Use of Spyder

WeChat official account tweet: https://mp.weixin.qq.com/s/b7zBCY0-8Hte7rrtpwksOQ

Spyder is an integrated development environment (IDE) for scientific computing using the Python programming language. It combines the advanced editing, analysis, and debugging capabilities of a comprehensive development tool with the data exploration, interactive execution, deep inspection, and visualization capabilities of a scientific package, bringing great convenience to users.

Open Spyder

In the start menu, find Anaconda3 -Spyder, click to enter; you can also send "Spyder" to the desktop shortcut, and then you can click the "Spyder" icon on the desktop to enter

image-20221019165917336

modify display theme

After entering Spyder, the page is as shown in the figure

image-20230107213829541

Although programmers generally prefer a black background (I don't know why, it may look taller), but we can also choose the background we like.

We can click Tools-Preference-Appearance, choose the display theme we like, click a different theme and then click the preview button on the right to see the rendering.

image-20230107213606754

image-20230107213757047

After selecting the display theme, click Apply. The system prompts that Spyder needs to be restarted, and click Yes.

modify language

We can click Tools-Preference-Application-Advanced settings to select "Simplified Chinese" and click "Apply" to switch to Chinese.

image-20230107213606754

image-20230107213529548

The core building blocks of Spyder

The three windows we use most often are the code editing area, variable browser, and IPython console .

image-20230107221042735

  • Code editing area: By default, it is located on the left side of the Spyder interface and is mainly used to write code files.

  • Variable browser: By default, it is located in the upper right corner of the Spyder interface. As long as it is a structural variable in Python memory, such as a data frame, list, dictionary, etc., it can be displayed here. Each line displays information about a variable, which includes variable name, variable Type, variable length, variable value. Double-click the corresponding variable line, you can also view all the data in the variable through a pop-up window.

  • IPython console: By default, it is located in the lower right corner of the Spyder interface. It is the core execution unit of Spyder, which executes file-based programming and interactive programming. The most important function is to interact with users, users can quickly verify whether the code running results meet expectations.

Basic operations in the code editing area

file operation

Common file operations mainly include new, open, and save

(1) new

Click "File" - "New File" in the menu bar, and a new file named "unnamed 0.py" is created. We write in the file, print('Hello,world')and our first program is compiled.

image-20230107221857989image-20230107222102519

(2) Save

After the program is compiled, we can click "File"-"Save" in the menu bar to save the file

image-20230107222248260

You can choose to save the folder and rename the file, such as "the first python file".

image-20230107222409866

(3) open

We click on the menu bar "File" - "Open" to open the file

image-20230107222656004

run operation

After we edit the code in the code editing area, click the shortcut key of "Run File" to run it.

image-20230107222758821

Basic operation of IPython console

Execution file programming

After we edit the code in the code editing area, click the shortcut key of "Run File" to run it, and the running result will be displayed in the Ipython console.

image-20230107223430100

Perform interactive programming

We can also edit the code directly in the Ipython console. After editing, enter the "Enter" key to run.

Summarize

  • Spyder code editing area: file-based programming, after editing all the code, let the interpreter execute it together; the file can be saved in the form of py.
  • Spyder's Ipython console: interactive programming, that is, there are questions and answers, and the running results will be returned after entering the code. Using Spyder's Ipython console is like making a draft. The running record of the code cannot be saved in the form of a file. You can only view the recently run historical code in the history.
  • You can make a draft in Spyder's Ipython console, write code in the code editing area, and finally submit a satisfactory answer sheet.

Guess you like

Origin blog.csdn.net/mfsdmlove/article/details/129396002