人海茫茫
相识真好

决战Python之巅(二)

前言

照例,每天学习之前先将昨天学习的新内容复习一哈。

知识回顾

昨天学习了7个课时,这里说明一下,每个课时平均下来差不多10分钟左右。昨天讲的大致就是Python的介绍及发展史Python解释器及Python 2或3Python的安装和Hello World变量(变量的作用和变量命名规范)用户交互和注释,最后是数字数据类型

Python的介绍及发展史

1989年,为了打发圣诞节假期,Guido开始写Python语言的编译器。Python这个名字,来自Guido所挚爱的电视剧Monty Python’s Flying Circus。他希望这个新的叫做Python的语言,能符合他的理想:创造一种C和shell之间,功能全面,易学易用,可拓展的语言。
1991年,第一个Python编译器诞生。它是用C语言实现的,并能够调用C语言的库文件。从一出生,Python已经具有了:类,函数,异常处理,包含表和词典在内的核心数据类型,以及模块为基础的拓展系统。
Granddaddy of Python web frameworks, Zope 1 was released in 1999
Python 1.0 – January 1994 增加了 lambda, map, filter and reduce.
Python 2.0 – October 16, 2000,加入了内存回收机制,构成了现在Python语言框架的基础
Python 2.4 – November 30, 2004, 同年目前最流行的WEB框架Django 诞生
Python 2.5 – September 19, 2006
Python 2.6 – October 1, 2008
Python 2.7 – July 3, 2010
In November 2014, it was announced that Python 2.7 would be supported until 2020, and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible
Python 3.0 – December 3, 2008
Python 3.1 – June 27, 2009
Python 3.2 – February 20, 2011
Python 3.3 – September 29, 2012
Python 3.4 – March 16, 2014
Python 3.5 – September 13, 2015

Python解释器及Python 2 or 3

解释器官方解释是:

解释器(英语:Interpreter),又译为直译器,是一种电脑程序,能够把高级编程语言一行一行直接转译运行。解释器不会一次把整个程序转译出来,只像一位“中间人”,每次运行程序时都要先转成另一种语言再作运行,因此解释器的程序运行速度比较缓慢。它每转译一行程序叙述就立刻运行,然后再转译下一行,再运行,如此不停地进行下去。

大致上的意思就是将你写的程序“翻译”成机器语言(至于为什么,在上一篇已和大家介绍过,这里就不做解释)。
Python解释器有很多种,而我们常用的、也是主要用的还是官方的解释器CPython(因为使用C语言写的,所以叫CPython),当你在计算机上装好Python,这个解释器将会自动安装在你的计算机上。

至于是Python 2还是Python 3,这个看个人需求,对于我们这种初学者来说还是推荐3.x版本,毕竟Python 3 is the present and future of the language!

In summary : Python 2.x is legacy, Python 3.x is the present and future of the language
Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of
extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is
under active development and has already seen over five years of stable releases, including version 3.3 in 2012,
3.4 in 2014, and 3.5 in 2015. This means that all recent standard library improvements, for example, are only
available by default in Python 3.x.
Guido van Rossum (the original creator of the Python language) decided to clean up Python 2.x properly, with less regard for backwards compatibility than is the case for new releases in the 2.x range. The most drastic improvement is the better Unicode support (with all text strings being Unicode by default) as well as saner bytes/Unicode separation.
Besides, several aspects of the core language (such as print and exec being statements, integers using floor division) have been adjusted to be easier for newcomers to learn and to be more consistent with the rest of the language, and old cruft has been removed (for example, all classes are now new-style, “range()” returns a memory efficient iterable, not a list as in 2.x).

Python的安装和Hello World

windows
https://www.python.org/downloads/

这是Python的安装包官网地址,有兴趣的小伙伴可以去看看,安装教程网上有很多我这就不再赘述,毕竟搬来搬去也很麻烦的呀。

安装完Python 3之后,我们可以测试一下是否安装成功:

1.win+R ——> 运行 ——>输入“Python”——>回车
2.如果弹出一下窗口说明安装成功了:
决战Python之巅(二)
3.退出:输入exit(),或者Ctrl+Z(或者直接关窗口!!!!)

既然安装成功了(这里默认你安装成功了,有问题google去),打开Python交互界面(即上图),输入:

print(“Hello world!”)

回车。
这样,Python的第一行代码就完成啦。
决战Python之巅(二)

变量

接下来就是变量。
照例:

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

这里,我们试着声明一个变量:

name = "Art3Mis"

变量名为: name,变量name的值为:“Art3Mis”;
同其他语言一样,Python变量的命名也是有规范的:
1.变量名只能是 字母、数字或下划线的任意组合;
2.变量名的第一个字符不能是数字;
3.以下关键字不能声明为变量名:
[‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘exec’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘not’, ‘or’, ‘pass’, ‘print’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’];

用户交互和注释

用户输入和输出:

name = input("What is your name ?")
print(name)

这两行代码就完成了一个输入输出的过程。
决战Python之巅(二)
执行完第一条,会弹出一句:What is your name?
这时候你需要输入一下东西给计算机,例如:Art3mis;
随后,计算机会将你输入的内容赋给name,我们输出一下name就可以看到现在name这个变量的值是你输入的内容。

注释

那什么是注释呢?
注释是你对当前代码的说明解释,这样能方便你或者其他程序猿看懂你写的代码,一般我们注释用 #(该加注释的就加,不该加的别乱加)。

PS:数字数据类型的话,我放在下一篇和其他数据类型一起介绍。

赞(0) 打赏
未经允许不得转载:老康的学习空间 » 决战Python之巅(二)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏