美文网首页
Python学习之Hello World

Python学习之Hello World

作者: 骄傲牛 | 来源:发表于2016-01-21 17:13 被阅读0次

自从大一之后就一直使用java到现在,最近总觉得应该学习一下其它语言。看了一下python,据说用来做网络爬虫和机器学习是一把好手,准备简单学习一下,充实一下自己。

下载与安装

官方下载:https://www.python.org,版本Python 3.5.1

Mac上的安装很简单,直接双击安装即可。

尝试写一下代码

启动和退出Python

打开终端,运行python3

$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

使用exit()或者quit()退出python

>>> quit()
$

执行简单的语句

运行python3后,可以执行简单的语句,比如基本运算和print

>>> (32+445)*343/213
768.1267605633802
>>> print('hello, world!')
hello, world!
>>>

可执行的python程序文件

使用文本工具将下面的代码保存为helloworld.py

print('hello, world!')

然后在命令行执行该文件

$ python helloworld.py
hello, world!

如果想要直接执行这个py文件,需要在文件里加一行注释

#!/usr/bin/env python3
print('hello, world!')

然后通过命令给文件以执行权限就可以执行该文件了

$ chmod a+x helloworld.py
$ ./helloworld.py
hello, world!

好了,现在我已经学会安装和运行python了

相关文章

网友评论

      本文标题:Python学习之Hello World

      本文链接:https://www.haomeiwen.com/subject/guilkttx.html