
#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:

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!
Python and Time: Making the Most of Your Study TimeApr 14, 2025 am 12:02 AMTo maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.
Python: Games, GUIs, and MoreApr 13, 2025 am 12:14 AMPython excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.
Python vs. C : Applications and Use Cases ComparedApr 12, 2025 am 12:01 AMPython is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.
The 2-Hour Python Plan: A Realistic ApproachApr 11, 2025 am 12:04 AMYou can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.
Python: Exploring Its Primary ApplicationsApr 10, 2025 am 09:41 AMPython is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.
How Much Python Can You Learn in 2 Hours?Apr 09, 2025 pm 04:33 PMYou can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.
How to teach computer novice programming basics in project and problem-driven methods within 10 hours?Apr 02, 2025 am 07:18 AMHow to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...
How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading?Apr 02, 2025 am 07:15 AMHow to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function






