The late scholar notes --Python a mysterious foundation

Python basis of a mysterious

[ Installation] and the introduction

A, Python Introduction                                                                                 

Introduction :

  python founder of Guido van Rossum ( Guido Van Rossum ). 1989 Christmas period year, Guido started writing can explain Python language syntax interpreter. Python name from Guido drama beloved Monty Python ' S Flying Circus . He hoped that this new called Python language, able to meet his ideal: to create a C and a shell between, full-featured, easy to use, scalable language.

The latest TIOBE rankings, Python catch PHP occupy the first 4 , Python advocating beautiful, clear, simple language is an excellent and widely used.

· Python be used in many fields, such as: data analysis, component integration, many networking services, image processing, numerical calculation and scientific computing. Almost all of the Internet industry's medium-sized enterprises are using Python , such as: Youtube , Dropbox , BT , Quora (China know almost), watercress, know almost, Google , Yahoo! , Facebook , NASA , Baidu, Tencent, car home, US group and so on.

1.web Development

  Python has a lot of free data library, web template system, as well as web library to interact server, you can realize web development, currently more famous Python web framework for the flask and Django . Both frameworks are very high efficiency

2. desktop development

  Python on the graphical interface development is also very powerful, you can take advantage of tkinter / PyQT framework to develop a variety of desktop software!

3. Network Programming

  Highly concurrent Twisted network framework, to python3 introduced asyncio make asynchronous programming becomes very easy (python2 no )

4. reptiles

  In the field of reptile python absolutely dominant position, and no one can

5. Artificial Intelligence

  This I do not say it, the earth will know python position in Artificial Intelligence

6. Cloud

  Python is engaged in cloud computing work we need to master a programming language, there is the fire of the cloud computing framework OpenStack is a Python development, if you want in-depth study and secondary development, you need to have Python skills.

7. Automated operation and maintenance

  Python is a comprehensive language to meet the needs of the vast majority of automated operation and maintenance, front and back end can do, working in this field, should be the design level, the framework of choice, flexibility, scalability, fault handling, and how to optimize and other aspects of learning.

8. Game Development

  In the network game development, Python , there are many applications, compared to Lua or C ++ , Python than Lua has a higher order of abstraction, with fewer business logic code describes the game as far as I know, "civilized" game It is python write

9. scientific computing

  97 Beginning in, NASA in the extensive use of Python making a variety of complex scientific computing, as NumPy, SciPy, Matplotlib, Enthought librarys development and many other libraries, so the Python more suited to do scientific computing, high draw quality 2D and 3D images. And scientific computing of the most popular commercial software Matlab compared, Python is a general-purpose programming language than Matlab application scripting language is used more widely .

 

Two, Python real application scenarios                                                                      

 


CIA: CIA website is to use Python developed by
NASA: US Space Agency (NASA) extensive use of Python for data analysis and computation
YouTube: the world's largest video site YouTube is to use Python developed
Dropbox: America's largest online cloud storage site, all implemented in Python, handle every day the site to upload and download files 1 billion
Instagram: America's largest photo-sharing social networking sites, more than 30 million photos every day to be shared, all with python development of
Facebook: a lot of basic libraries are implemented by Python the
linux system: the world's most popular Linux distribution version of yum package management tools is to use python development of
watercress : almost all of its services are by Python development
know almost : the largest Q & a community, by Python development (abroad Quora)
Chunyu Doctor: well-known online medical sites with Python development
in addition to the above, as well as Sohu, Jinshan, Tencent, Shanda, Netease, Baidu, Alibaba, Taobao , potatoes, Sina, shell and other companies are using Python complete a variety of tasks.

 

Three , Windows install python interpreter                                                             

Open official website  https://www.python.org/downloads/windows/  Download Center

 

 

 

 

 

 

Testing the installation : Enter keyword under the python cmd, if they can enter the interactive interface for OK

 

1.pycharm安装方法

https://blog.csdn.net/pdcfighting/article/details/80297499

 

2.pip介绍

pip的用法其实跟linux的yum很像,它可以帮我们安装python所需要的环境包,并且可以包解决依赖关系

列出已安装的包

pip list

安装要安装的包

pip install xxx

安装特定版本

pip install django==1.1.5

 

导出python的环境

pip freeze > requestment.txt

从导出的python环境中安装所需要的包

pip install -r requestment.txt

卸载导出的python环境中的包

pip uninstall -r requestment.txt

升级包 

pip install -U <包名>

显示包所在的目录

pip show -f <包名>

搜索包

pip search <搜索关键字>

查询可升级的包 

pip list -o

下载包而不安装 

pip install <包名> -d <目录> pip install -d <目录> -r requirements.txt

更换国内pypi镜像 

阿里:https://mirrors.aliyun.com/pypi/simple 
豆瓣:http://pypi.douban.com/simple 
中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/ 

pip install <包名> -i http://pypi.v2ex.com/simple

指定全局安装源 

unix和macos,配置文件为:$HOME/.pip/pip.conf 
windows上,配置文件为:%HOME%\pip\pip.ini

(1):在windows文件管理器中,输入 %APPDATA%

(2):会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件

(3):在新建的pip.ini文件中输入以下内容,搞定文件路径:"C:\Users\Administrator\AppData\Roaming\pip\pip.ini"

 

[global]

timeout = 6000

index-url = http://pypi.douban.com/simple

 

3.创建python的虚拟环境

为什么需要虚拟环境:

如果你现在用Django 1.10.x写了个网站,然后你的领导跟你说,之前有一个旧项目是用Django 0.9开发的,让你来维护,但是Django 1.10不再兼容Django 0.9的一些语法了。这时候就会碰到一个问题,我如何在我的电脑中同时拥有Django 1.10和Django 0.9两套环境呢?这时候我们就可以通过虚拟环境来解决这个问题。

1安装虚拟环境:

virtualenv是用来创建虚拟环境的软件工具,我们可以通过pip或者pip3来安装

pip install virtualenv    #windows系统

pip3 install virtualenv    #linux系统

创建虚拟环境:

创建虚拟环境非常简单,通过以下命令就可以创建了:

virtualenv [虚拟环境的名字]

进入虚拟环境:

虚拟环境创建好了以后,那么可以进入到这个虚拟环境中,然后安装一些第三方包,进入虚拟环境在不同的操作系统中有不同的方式,一般分为两种,第一种是Windows,第二种是*nix:

1) windows进入虚拟环境:进入到虚拟环境的Scripts文件夹中,然后执行activate。

2) Linux进入虚拟环境:source /path/to/virtualenv/bin/activate
一旦你进入到了这个虚拟环境中,你安装包,卸载包都是在这个虚拟环境中,不会影响到外面的环境。

退出虚拟环境:

退出虚拟环境很简单,通过一个命令就可以完成:deactivate。

 

创建虚拟环境的时候指定Python解释器:

在电脑的环境变量中,一般是不会去更改一些环境变量的顺序的。也就是说比如你的Python2/Scripts在Python3/Scripts的前面,那么你不会经常去更改他们的位置。但是这时候我确实是想在创建虚拟环境的时候用Python3这个版本,这时候可以通过-p参数来指定具体的Python解释器:

virtualenv -p C:\Python36\python.exe [virutalenv name]

2virtualenvwrapper

virtualenvwrapper这个软件包可以让我们管理虚拟环境变得更加简单。不用再跑到某个目录下通过virtualenv来创建虚拟环境,并且激活的时候也要跑到具体的目录下去激活。

安装virtualenvwrapper

linuxpip install virtualenvwrapper

windowspip install virtualenvwrapper-win

virtualenvwrapper基本使用:

1)创建虚拟环境:

 mkvirtualenv my_env

那么会在你当前用户下创建一个Env的文件夹,然后将这个虚拟环境安装到这个目录下。
如果你电脑中安装了python2和python3,并且两个版本中都安装了virtualenvwrapper,那么将会使用环境变量中第一个出现的Python版本来作为这个虚拟环境的Python解释器。

2)切换到某个虚拟环境:

 workon my_env

3)退出当前虚拟环境:

 deactivate

4)删除某个虚拟环境:

 rmvirtualenv my_env

5)列出所有虚拟环境:

 lsvirtualenv

6)进入到虚拟环境所在的目录:

 cdvirtualenv

修改mkvirtualenv的默认路径

我的电脑->右键->属性->高级系统设置->环境变量->系统变量中添加一个参数WORKON_HOME,将这个参数的值设置为你需要的路径。

创建虚拟环境的时候指定Python版本

在使用mkvirtualenv的时候,可以指定--python的参数来指定具体的python路径:

    mkvirtualenv --python==C:\Python36\python.exe hy_env

、变量                                                                                 

变量是什么?什么是变量?变量有什么好处?

变量是一种使用方便的占位符,用于引用计算机内存地址,该地址可以存储Script运行时可更改的程序信息。例如,可以创建一个名为ClickCount的变量来存储用户单击Web页面上某个对象的次数。使用变量并不需要了解变量在计算机内存中的地址,只要通过变量名引用变量就可以查看或更改变量的值。在例如:咱们平时玩的游戏都有level,打怪就升级,那个level就是变量

1变量定义的 规范:

变量名只能是字母、数字或下划线的任意组合

变量名的第一个字符不能是数字

变量名不能为关键字,比如 and,as,break,class,continue,def,del............

变量名字尽量起个个有意义的名字,比如:name=‘张三’,不要词不达意,比如:aaa='张三'

变量名字不要起过长

变量名字尽量不要起拼音或者汉字

 

2变量应该具有的属性或者特征

name='张三'

id,type,value

id——代表变量的内存地址,为一串数字表示

type——代表变量的数据类型

value——代表等号右边的值

3个特点缺一个都不叫变量

 

3python的小整数池

在交互模式下python有一个小的整数池,他的范围是[-5,256],这么做的好处是避免浪费空间和资源;

只要是在这个数值内,内存地址都一样;

pycharm中,pycharm出于对性能的考虑会扩大这个整数池,至于扩大到多少,视内存而定。

 

、常量                                                                                  

常量即代表不变的量,其实在python里不存在真正不变的量,只不过潜规则在我们想定义一个常量的时候变量名为大写即为常量:

比如:一个人的年纪不断的增长,那么年纪就叫常量,如果这个人死了,那么他的年纪就被定格在了那一年的年纪上,这个时候年纪就是常量

AGE=60

、用户与程序(python)交互                                                                           

首先来说什么是交互,交互就跟人与人对话一样,你有来言,我有去语,能够对话...能够沟通,那么用户怎么跟程序去对话呢?这时候我们可以调用python的一个内置函数,叫:input

 

#例子

name = input()

print(name)

#如果你想让程序有提示信息

name = input("what's your name?:")

print(name)

 

、注释                                                                                 

随着代码越来越多,如果你不写注释的话可能过几天连自己写的代码都不知道写的什么意思,更何况是别人了,因此就需要有注释来提示用户

单行注释可以用#表示,#号右边的为注释内容

如果要多行注释可以用三个单引号:'''   ''',左右两边一边13引号中间的部分就是注释的内容

 

 

 ——————————————————————分割线————————————————————————

Guess you like

Origin www.cnblogs.com/feige2L/p/10945535.html