如何使用示例运行/执行Python脚本教程?

Python is popular programming and scripting language. This popularity causes different use cases for Python scripts and codes. In this tutorial, we will learn what is a Python script, how to run Python code and script from the command line, GUI, IDe, etc.

Python是流行的编程和脚本语言。 这种流行导致了Python脚本和代码的不同用例。 在本教程中,我们将学习什么是Python脚本,如何从命令行,GUI,IDe等运行Python代码和脚本。

什么是Python脚本? (What Is Python Script?)

The python script is some code written in Python which can be run as an application or from a shell easily. Python scripts have some structures like below.

python脚本是一些用Python编写的代码,可以作为应用程序运行,也可以从shell轻松运行。 Python脚本具有以下类似的结构。

  • Import required modules

    导入所需的模块
  • Define Class, Function and other structures

    定义类,函数和其他结构
  • Execute and run code and script from imported modules, defined classes, and functions

    从导入的模块,已定义的类和函数执行并运行代码和脚本

示例Python脚本(Example Python Script)

Below we can find an example script which will simply print some text by using functions to the standard output.

在下面我们可以找到一个示例脚本,该脚本将通过使用函数将一些文本简单地输出到标准输出。

import os

def PrintHello(str):
    print ("Hello World "+str)

PrintHello("Poftut.com")
What Is Python Script?
What Is Python Script?
什么是Python脚本?

We can use the command-line interface or the operating system terminal in order to run and execute Python scripts and code. There is a two-way method to run the Python script. First is using the python interpreter and provide the script file path where the interpreter will read the script file and run it. Second is making the script file executable and running from the command directly providing the script file name like a command or executable.

我们可以使用命令行界面或操作系统终端来运行和执行Python脚本和代码。 有两种方法可以运行Python脚本。 首先是使用python解释器并提供脚本文件路径,解释器将在该路径中读取脚本文件并运行它。 其次是使脚本文件可执行,并从命令运行,直接提供脚本文件名,例如命令或可执行文件。

使用Python解释器运行 (Run with Python Interpreter)

We can use Python interpreter which can be run directly from the command line. For Python2 python2 for Python3 python3interpreter can be used. also the interpreter should be added to the OS Path or environment variables which are described below for Windows operating

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值