美文网首页
python入门引导(一·初识)

python入门引导(一·初识)

作者: 一只野生猿 | 来源:发表于2017-10-16 00:23 被阅读0次

初识python

python,当今十大热门语言之一,更是机器学习的领先者

python于1989年,由荷兰人Guido van Rossum(吉多·范罗苏姆)发明

吉多给python的定位是简单,高效,使得python易学习,易阅读,易维护,从而成为受欢迎的语言,其他关于python的前世今生我也就不过多描述了,百度一下很全面,下面我们开始这一章的内容,初识python。

一· python能干什么

python什么都能做,比如web开发,爬虫开发,数据分析,游戏开发,自动化,人工智能等等,俗话说,人生苦短,我用python,python在手,天下我有。

二· python版本的选择

众所周知,python有2.x和3.x的版本,python官网推荐使用3.x的版本,本系列教程也将使用python3.6的版本。

Short version: Python 2.x is legacy, Python 3.x is the present and future of the language

三·python安装

  • mac安装
    mac自带的是python2.7的版本,需要再安装一个3.6的
    官网下载地址:python3.6.3
    百度云盘下载:python3.6.3 提取密码: cvzp
    安装过程默认即可
  • windows安装
    官网下载地址:python3.6.3
    百度云盘下载:python3.6.3 提取密码:tuqq
    安装过程默认即可
    (由于官网下载可能会比较慢,百度云盘链接是本人从官网下载然后上传到百度,请放心下载)

四·python交互式环境

python的交互式是一个很好用的调试工具,也做为我们认识python程序的一个入口。

  • windows系统打开cmd,输入python,然后回车
  • mac系统打开terminal,输入python,然后回车


    python交互式环境

    (由于我是mac系统,有两个版本的python,所以进入3.x系统使用的是python3这个命令)
    接下来,我们就可以在交互式环境下玩一玩python了,下面是一些例子,对于它们的具体用法可自行百度,或者等待后面的教程慢慢学习,这里的目的只是为了帮助认识python。

# 打印当前时间
>>> import time
>>> time.ctime()
'Sun Oct 15 23:52:52 2017'
>>> time.time()
1508083060.4198642
# 基础运算
>>>2 ** 10
1024
>>>25 - 12
13
>>>25 / 2
12.5
>>> "A" * 72
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
# 打印字符串
>>>print("Hello world!")
Hello world!
# python禅道
>>>import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

四·python代码文件编写

python代码文件以py作为文件的后缀名,我们把刚才在交互式输入的语句写入到python代码文件中。
first.py

import time
print(time.ctime())
print(time.time())
print(2 ** 10)
print(25 - 10)
print(25 / 2)
print("A" * 72)
print("Hello World!")
import this

之后通过python命令来运行它,windows在cmd里面,mac在terminal里面
执行python first.py,就会得到如下结果

Mon Oct 16 00:09:03 2017
1508083743.0646641
1024
15
12.5
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Hello World!
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

五·小结

本章简单介绍了python的用途,安装运行python,python交互式环境的使用,以及python代码文件的编写和执行,目的是为了让大家对python有个初步的了解,下一章节将会为大家介绍python变量,数据类型相关的基本知识。
本人第一次写文章,如有不对的地方请多多指教。

相关文章

网友评论

      本文标题:python入门引导(一·初识)

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