Hello World程序
在linux 下创建一个文件叫hello.py,并输入
print ('hello,word')
然后执行:python3 hello.py ,输出:
[root@IDC-SZ-156 python]# python3.6 hello.py
hello,world
指定解释器
上一步中执行 python hello.py 时,明确的指出 hello.py 脚本由 python 解释器来执行。
如果想要类似于执行shell脚本一样执行python脚本,例: ./hello.py
,那么就需要在 hello.py 文件的头部指定解释器,如下:
1 #!/usr/bin/env python 2 print('hello,world')
如此一来,执行: ./hello.py
即可。
ps:执行前需给予 hello.py 执行权限,chmod u+x hello.py
在交互器中执行
[root@IDC-SZ-156 python]# ipython3 Python 3.6.2 (default, Sep 18 2017, 14:58:30) Type "copyright", "credits" or "license" for more information. IPython 1.2.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: print('hello,world') hello,world