第一个python程序--hello,world

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

 

  

 

 

转载于:https://www.cnblogs.com/sunhao96/p/7543266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值