Syder 使用指南

本指南介绍了如何在Spyder环境中执行Python程序,包括在控制台调用函数、检查对象、重置名称空间和遵循PEP8编码规范。通过实例展示了如何运行、调试和管理代码,适合Python初学者。
摘要由CSDN通过智能技术生成
# Demo file for Spyder Tutorial
# Hans Fangohr, University of Southampton, UK

def hello():
    """Print "Hello World" and return None."""
    print("Hello World")

# Main program starts here
hello()

Please create a new file in the Spyder Editor pane (with File ‣ New file, or Ctrl-N/ Command-N). Then copy and paste the code inside the box above into the file, and save it with the name hello.py.

To execute the program, select Run ‣ Run from the menu (or press F5), and confirm the Run settings if required.

If this is your first time running something, you should see an output like this:

In [1]: runfile('/File/Path/hello.py', wdir=r'/File/Path')
Hello World

In [2]:

注意:在runfile()中显示的特定路径将取决于您保存文件的位置,但这是Spyder自动插入的。

Python会逐行读取文件,而忽略注释(即以#符号开头的行)。

当遇到def关键字时,它知道在此行和下一行(一个或多个)中定义了一个函数。 def hello()之后的所有缩进行均属于函数主体。

请注意,此时已在文件中创建了函数对象,但尚未调用该函数(即未执行)。

当Python解释器遇到写在最左侧列中的命令(除def …和一些其他关键字之外)时,它将立即执行这些命令。

在hello.py文件中,只有读取hello()的行会实际调用(即执行)名称为hello的函数。

如果从程序中注释或删除行hello()并再次运行整个文件(通过按F5或选择Run‣Run),将不会打印任何内容(因为已定义但未调用hello函数,即未执行&#x

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值