Terminal and file run python code

How to create python file? Create a new txt, and then modify the suffix to .py,

 

Then modify the opening method to Notepad, write a line of code, and then close

 

 How to run it next? Let him output this piece of code

win+R cmd Enter, then enter python + file address

It is relatively cumbersome for us to find the file address. An easy way is to directly drag the file into the cmd window to automatically obtain the file address  . As shown in the figure below, you can output hello

Next, I will explain two ways to run python programs:

1. Terminal operation

Enter python, switch to the python terminal, then enter the print command and press Enter to output

 Here comes the question: How do I save this line of code after I finish writing it?

Answer: It cannot be saved, so this method is generally not used

How to exit python terminal?

Three ways: exit(), quit(), shortcut key ctrl+z enter

 New question: Do we see that the terminal window is all black and white? Looking at it is strenuous, how to let him have a highlight display?

Answer: ipython is used at this time , let's install ipython first:

 pip install ipython -i https://pypi.douban.com/simple

If the installation fails and the error is reported, you can move to view:  (use of pip): You are using pip version 21.2.4; however, version 23.0.1 is available.You should consider_suoh's Blog's Blog-CSDN Blog

 After the installation is successful, enter ipython, you can see that it is much better than the python interface

 Neither python nor ipython above can guarantee the preservation of the code, so we will choose the second method

Two, pycharm

        Although the method described above has been able to improve our coding speed, it still cannot meet the more complex requirements in our development. In general, we need tools to help us quickly build the environment, write code and run the program.
The concept of IDE
        IDE (Integrated Development Environment) is also known as an integrated development environment. To put it bluntly, there is a software with a graphical interface, which integrates functions such as editing code, compiling code, analyzing code, executing code, and debugging code. In our Python development, the most commonly used IDE is Pycharm.
        pycharm is an IDE developed by the Czech company JetBrains, which provides code analysis, graphical debugger, integrated tester, integrated version control system, etc., and is mainly used to write Python code.

The pytharm installation tutorial is as follows: PyCharm installation tutorial (Windows) | rookie tutorial

After creating a new pythonPractice project in pycharm, select pythonPractice and right-click to create a new python file.

We create a new test.py, write a print output, right click on the blank space and select run test to output 

 

 Supplement: We want to add personal information comments, such as author, time, etc., at the beginning of the newly created py file every time. How?

 Select the settings under the file

# _*_ coding : utf-8_*_
# @Time : ${DATE} ${TIME} 
# @Author: suoheng
# @File : ${NAME}
# @Project : ${PROJECT_NAME}

 At this point, we create a new testName file, and we can see that the comment has been automatically added 

Guess you like

Origin blog.csdn.net/qq_41579104/article/details/130086982