D:\pythonwork>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> the_word_is_flat = 1;
>>> if the_word_is_flat :
... print("be careful not to fail off");
...
be careful not to fail off >>> . 错误处理;
如果解释器在解析命令时出现错误,那么Interpreter将打印error message和a stack trace,和其他语言类似,在python中也存在错误处理,这将在后面介绍。 .python解释器启动代码
The Interactive Startup File;
python解释器可以设置启动时运行的命令,可以通过设置环境变量PYTHONSTARTUP来实现,如下:
Starup.py文件:
print("python Interpreter is going to start !");
这时,重新启动python解释器时结果:
D:\pythonwork>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
python Interpreter is going to start !
>>>. 执行一个python module;
5.1 python文件注释
python文件中可以使用两种类型的注释,如果是单行注释,可以使用#号:
# this is a comment a = 10;
如果是多行注释的话,可以使用''':
'''
python tourial :
An Informal Introduction to Python '''
5.2 如何支持中文注释
可以通过设置.py文件的编码方式来支持中文注释: