Where can python programs be run?

silencement
Release: 2019-06-19 17:22:40
Original
10240 people have browsed it

Where can python programs be run?

#There are two ways to run Python, one is Python interactive mode; the other is to run the .py file directly.

The first Python interactive mode
Enter python under cmd to enter.
In command line mode, you can execute python to enter the Python interactive environment.
See that>>> is in the Python interactive environment:

Where can python programs be run?

In the Python interactive environment, you can only enter Python code and execute it immediately.
So the advantage is that you can get the result in one go, but the disadvantage is that it cannot be saved, and you have to type it again next time you want to run it.

The second type is to run the .py file directly
Can I run the .py file directly like the .exe file?
It doesn't work on windows, but it does on mac and linux. The method is to add a special comment on the first line of the .py file:
#! usr/bin/env python3
print("hello world") # For example
After that, give hello.py execution permission through the command:
$ chmod a x hello.py
You can directly It runs on mac and linux.

Saving and running Python programs
1. Available editors
notepad, sublime text, pycharm, etc.
(1)notepad
Create a file, write the program into the file, and save it in .py format.
Run: In cmd, go to the folder of program.py and enter >python ***.py.
(2)sublime text
It’s free to use, but if you don’t pay, a prompt box will pop up.
(3)pycharm
You need to pay to use it. The trial period is 30 days. There are also many registration codes online.
Method 1: In the registration interface, select license serve, fill in http://idea.lanyus.com/71, and click OK.
Method 2: In the registration interface, select activationcode, open the URL http://idea.lanyus.com/71, and click the "Get Registration Code" button. Copy the registration
code of the pop-up box.
Method 3: After installing pycharm, adjust the computer system time, choose to apply for a 30-day trial on the registration interface, exit pycharm, and then set the computer time back.
Method 4: Install pycharm and choose a 30-day trial on the registration interface. Open help->register in the pycharm menu, open the URL http://idea.lanyus.com/71,
click the "Get Registration Code" button, and copy.

Summary:
What is the difference between Python’s interactive mode and running the .py file directly?
Enter python directly to enter the interactive mode, which is equivalent to starting the Python interpreter, but waiting for you to enter the source code line by line, and executing each line entered.
Directly running the .py file is equivalent to starting the Python interpreter, and then executing the source code of the .py file at once. There is no opportunity to enter the source code interactively.

The above is the detailed content of Where can python programs be run?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template