zoukankan      html  css  js  c++  java
  • python介绍

    1、面向对象(越接近人类思维习惯,高级语言)的解释型(需要解释器,可以立刻执行,如shell/javescript)计算机程序设计语言,荷兰人1989年发明,第一个公开发行版1991年发布。

    2、python版本:python2和python3不兼容。现阶段大部分公司使用python2,python2 用于爬虫,python3 用于人工智能/大数据比较多。

    3、python优点:语法简单、弱类型语言、容易学习、免费/开源、高级语言(不需要关注内存使用一类的底层细节)、可移植性(多种平台上运行)、解释性、面向对象、可扩展性、丰富的库(机器学习、人工智能、爬虫库)、规范的代码(强缩进的方式具有极佳的可读性)。

    编译型语言:源码----编译-----二进制文件----操作系统运行。

    解释型语言:源码----解释器读取源码-------解释器翻译源码得到二进制文件--交给计算机运行 。

    4、应用场景:

    web应用开发:通过浏览器可以访问的系统。一些第三方库可以让程序员轻松的开发和管理复杂的web程序。

    操作系统管理、服务器运维的自动化脚本:介于C语言和shell语言之间创造的解释型语言。

    科学计算机器学习:Numpy、Scipy等可以让python程序员编写科学计算机程序。

    服务器软件(网络软件):阿里云计算,对各种网络协议支持很完善。用于编写服务器软件、网络爬虫、提供多种工具,广泛用于编写高性能的服务器软件。

     python的第一个脚本:

    [root@localhost python]# chmod u+x 01.py 
    [root@localhost python]# ll
    total 8
    -rwxr--r--. 1 root root 21 May  3 06:50 01.py
    -rwxr--r--. 1 root root 57 May  1 04:16 01.sh
    -rw-r--r--. 1 root root  0 May  1 04:02 1.java
    [root@localhost home]#vi 01.py 
    [root@localhost home]# 
    #!/usr/python-3.6.5/bin/python3  //指定解释器,可以通过./执行脚本,
    print("hello,world")
    :wq
    [root@localhost python]# ./01.py
    hello,world
    [root@localhost python]# python3 01.py   //脚本中未指定解释器时,使用此方式执行py脚本
    hello,world
    [root@localhost python]# python 01.py //默认位python2
    hello,world
    
    [root@localhost python]# python3  //交互式界面执行命令,易用性不好,推荐使用ipython执行交互性操作,交互界面可以直接看到结果,并且可以命令补全。
    Python 3.6.5 (default, May 1 2018, 00:59:27) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print('hello')
    hello
    >>>exit()
    [root@localhost python]# ipython3
    In [1]: print("hello") //鼠标可以自由移动,操作方便
    hello
    
    In [2]: ls //可以查看linux命令
    01.py* 01.sh* 1.java
    
    In [3]: %d //tab键可以命令补全和选择
    %debug %dirs 
    %%debug %doctest_mode 
    %dhist
    
    In [4]: exit //退出执行exit或quit即可
    [root@localhost python]#
    
    In [4]: quit
    [root@localhost python]#

     设置行号和制表位:

    [root@localhost python]# vi ~/.vimrc
    set nu //设置行号
    set ts=4 //设置制表符 tabstop的缩写
    set sw=4 //向左向右移动四个空格 shiftwidth的缩写

    注释和中文编码

      3 #define ...  //单行注释
      4 def main():  //多行注释'''   '''
      5     '''
      6     print hello
      7         
      8     '''
      9     print("hello")

    python3中默认支持中文编码,python2中默认不支持中文编码。

    ASCII 1个字符   

    GB2312  2个字节  处理中文 国标编码

    Unicode 4个字节,统一编码标准 UTF-16/32 ,所有的语言都使用此编码格式。

    UTF-8 可变长编码 将unicode字符根据不同的数字大小编码成1-6个字节 英文字母被编码成一个字节,汉字通常是3个字节;

    6 乱码的本质:编码格式不统一。

    解决:

    # coding=utf-8 建议中间不要有空格

    # -*-coding: utf-8 -* 

    [root@localhost python]#vim 01.py
      1 print('hello,world')
      2 #这是中文的注释
    :wq
    [root@localhost python]# python3 01.py 
    hello,world
    [root@localhost python]# python 01.py  
      File "01.py", line 2
    SyntaxError: Non-ASCII character 'xe8' in file 01.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
    [root@localhost python]#vim 01.py
      1 #coding=utf-8 //统一编码格式
      2 print('hello,world')
      3 #这是中文的注释
    :wq
    [root@localhost python]# python 01.py  
    hello,world
  • 相关阅读:
    WIN8 下 Hyper-V和Vmware Workstation
    小技巧总结
    工具软件
    php开发入门
    docker的用法总结
    [工具] 同步本地文件夹与VPS中的文件夹
    读书笔记之《The Art of Readable Code》Part 3
    读书笔记之《The Art of Readable Code》Part 2
    正则表达式小试牛刀
    读书笔记之《The Art of Readable Code》part 1
  • 原文地址:https://www.cnblogs.com/zhaoyujiao/p/8976500.html
Copyright © 2011-2022 走看看