zoukankan      html  css  js  c++  java
  • Python学习【第一篇】Python简介

    Python简介

    Python前世今生

    Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言。

    现在,全世界差不多有600多种编程语言,但流行的编程语言也就那么20来种。如果你听说过TIOBE排行榜,你就能知道编程语言的大致流行程度。这是最近10年最常用的10种编程语言的变化图,最新的TIBOE排行榜,Python已经坐稳了第五的宝座,甩php好几条街。

    由上图可见,Python整体呈上升趋势,反映出Python应用越来越广泛并且也逐渐得到业内的认可!!!

    Python可以应用于众多领域,如:数据分析、组件集成、网络服务、图像处理、数值计算和科学计算等众多领域。目前业内几乎所有大中型互联网企业都在使用Python,如:Youtube、Dropbox、BT、Quora(中国知乎)、豆瓣、知乎、Google、Yahoo!、Facebook、NASA、百度、腾讯、汽车之家、美团等。互联网公司广泛使用Python来做的事一般有:自动化运维、自动化测试、大数据分析、爬虫、Web等。

    注:上述重点字体表示该公司主要使用Python语言开发

    为什么是Python而不是其他语言?

    C和Python、Java、C#等

      C语言:代码编译得到 机器码,机器码在处理器上执行,每一条指令控制CPU工作

      其他语言:代码编译得到 字节码,虚拟机执行字节码并转换成机器码后再在处理其上执行

      Python和C Pyhton这门语言是由C开发而来

        对于使用:Python的类库齐全并且使用简洁,如果要实现同样的功能,Python 10行代码可以解决,C可能就需要100行甚至更多。

        对于速度:Python的运行速度相较与C,绝逼是慢了

      Python和Java、C#等

        对于使用:Linux原装Python,其他语言没有;以上几门语言都有非常非常丰富的类库支持

        对于速度:Python在速度上可能稍显逊色

    所以,Python和其他语言没有什么本质上的区别,其他区别在于:擅长某领域、人才丰富、先入为主。

    Python的种类

    ·Cpython

      Python的官方版本,使用C语言实现,使用最为广泛,CPython实现会将源文件(.py文件)转换成字节码文件(.pyc文件),然后运行在Python虚拟机上。

    ·Jython

      Python的Java实现,Jython会将Python代码动态编译成Java字节码,然后在JVM上运行。

    ·IronPython

      Python的C#实现,IronPython将Python代码编译成C#字节码,然后在CLR上运行。(与Jython类似)

    ·PyPy(特殊)

      Python实现Python,将Python的字节码字节码再编译成机器码。(它的目标是执行速度。)

    ·RubyPython、Brython...

    以上除PyPy之外,其他的Python的对应关系和执行流程如下:

    PyPy,在Python的基础上对Python的字节码进一步处理,从而提升执行速度!

    Pthon 2 or 3?

    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).

    ps:本文主要还是围绕python 3 来进行学习,部分python 2的代码会通过注释提醒。

    Python环境

    安装Python

      Windows:

    1、下载安装包
        https://www.python.org/downloads/
    2、安装
        默认安装路径:C:python27
    3、配置环境变量
        【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用 ; 分割】
        如:原来的值;C:python27,切记前面有分号
    

      

      Linux:

    无需安装,原装Python环境
       
    ps:如果自带2.6,请更新至2.7

    更新Python

      Windows:

    卸载重新安装即可 

      Linux:

        Linux的yum依赖自带Python,为防止错误,此处更新其实就是再安装一个Python

    查看默认Python版本
    python -V
       
    1、安装gcc,用于编译Python源码
        yum install gcc
    2、下载源码包,https://www.python.org/ftp/python/
    3、解压并进入源码文件
    4、编译安装
        ./configure
        make all
        make install
    5、查看版本
        /usr/local/bin/python2.7 -V
    6、修改默认Python版本
        mv /usr/bin/python /usr/bin/python2.6
        ln -s /usr/local/bin/python2.7 /usr/bin/python
    7、防止yum执行异常,修改yum使用的Python版本
        vi /usr/bin/yum
        将头部 #!/usr/bin/python 修改为 #!/usr/bin/python2.6
    

      

  • 相关阅读:
    zoj1137 poj1466
    poj3041
    zoj1455
    hdu1160 FatMouse's Speed
    zoj2770
    hdu1469
    hdu3169
    Mapped exception to response: 500 (Internal Server Error)
    Mapped exception to response: 500 (Internal Server Error)
    object is not a function
  • 原文地址:https://www.cnblogs.com/Bourbon-tian/p/5883031.html
Copyright © 2011-2022 走看看