Pythoy修炼之路
路漫漫其修远兮,吾将上下而求索...
编程语言众多,徘徊在C、C#、Java、PHP等十字路口,看到哪个领域大牛的成功,便想打开那扇窗,反反复复,犹豫不决,终无所获。
个人认为选择一门语言,要根据自身的编程基础,计算机基础,以及所选语言能实现哪些目标来选择当前想学习的语言
生活的节奏让我必须做出选择,我要打开这扇魔幻的世界之窗----Python编程之路;希望和志同道合码农一起修炼,升级。
Python是什么
编译型与解释型
编译型语言:对于程序在一个文件中,编译后直接生成一个可执行文件,可以直接运行;对于较为复杂的项目,代码分为各个模块并且保存在各个源文件中,所以需要对各个文件编译生成相对应的目标文件而不是可执行代码,此时需要将这些目标文件“链接”起来才能运行。
解释型语言:只在程序运行时,才一条一条的解释成机器语言给计算机来执行,所以运行速度比较慢。
动态语言与静态语言
动态语言:指在运行期间才去做数据类型检查的语言,也就是说,在用动态类型的语言编程时,永远也不用给任何变量指定数据类型,该语言会在你第一次赋值给变量时,在内部将数据类型记录下来。
静态语言:数据类型是在编译其间检查的,也就是说在写程序时要声明所有变量的数据类型,C/C++是静态类型语言的典型代表。
强类型定义语言与弱类型定义语言
强类型定义语言:一旦一个变量被指定了某个数据类型,如果不经过强制转换,那么它就永远是这个数据类型
弱类型定义语言:数据类型可以被忽略的语言。它与强类型定义语言相反, 一个变量可以赋不同数据类型的值,例如即可以当作字符串处理也可以当作数字处理,如shell
总而言之,Python是一门动态强类型定义的解释型语言。
可以参考Alex老师的总结:<strongwww.cnblogs.com/alex3714/articles/5465189.html
Python能做什么
我认为学习一门语言首先需要了解我们用这门语言能实现什么,而不是单纯的抱着一本编程书从print hello world 一直往下啃,也许学完基础后就会发现这本书很难实现自己的目标,然而学习愿望慢慢减小,直至胎死腹中;也许年轻觉得这点时间还可以挥霍,但是一切回到原点徘徊在十字路,徒留迷茫。
Python给人的第一印象也许是,“Python是什么鬼”,“什么编程语言”,“能做什么”;不着急,下图给了我们回答。也许会发现Python居然能实现这么多功能,我也不知道,我也是小白,也许他们是我的目标。
Python怎么开始
选择合适的Python版本是学习python的关键,由于python2.x和python3.x可以说有很大差别,命令名称与命令格式都有所改变。下图将展示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
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编程之编码
Python使用utf-8编码规范,支持中文,所以在文件可申明编码规范,如下:
# -*- coding: utf-8 -*-
Python3默认使用utf-8编码规范,支持中文;Python2默认使用ASCII编码,不支持中文,必须在代码开始处加上# -*- coding: utf-8 -*-,声明使用utf-8编码,支持中文
编码参考:https://www.cnblogs.com/yuanchenqi/articles/5956943.html