一.python概述
1.优点
•简单、优雅、明确
•有强大的第三方库模块
•可跨平台移植
•一种面向对象的语言
2.缺点
•代码执行速度慢,相比C语言,不过现在python的
异步并发框架导致执行速度慢;
•python是开源的编程语言,代码不能加密
但是为什么python比c运行速度慢 还要用呢?
1.运行速度上相比c要慢许多
C: 1000行 0.02s
python: 20行 0.2s
2.但是python内涵大量的函数库 可能编写同样功能的内容 代码行数明显少
3.因为程序运行也需要时间,相对程序运行时间来说代码执行速度的影响太小 人几乎感觉不到
比如下载音频文件,网速有限制,相对于人差别并不大,但c写的时间长。
10min+0.02s
10min+0.2s
二.python安装
•访问python官网:www.python.org;
•Linux操作系统上一般iso镜像里面自带,直接通
过yum安装;
注意:
•- python2.6是一个过渡版本,既可以执行,又包含
python3.0的新特性;
•- 现在企业实战应用python版本为2.7版本;
•- python2.7是python2.x系列最后一个版本,不
会再有python3.0;
三.交互环境执行程序
保存在内存中,突出即删除
>>> print hello shell ##打印内容 用引号引起来 一个完整的字符
File "<stdin>", line 1
print hello shell
^
SyntaxError: invalid syntax
>>> print "hello world"
hello world
>>> zl = "LULUBAO" ##定义一个变量的内容
>>> print zl ##打印变量
LULUBAO
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit () ##退出
四.编辑器编写脚本
•#!/usr/bin/python 这种写法表示直接引用系统的默认的
Python 版本;
•#!/usr/bin/env python 这种写法表示,引用环境变量里面
自定义的 Python 版本, 具有较强的可移植性;
[root@foundation10 yum.repos.d]# which python /bin/python ##解释器位置 [root@foundation10 yum.repos.d]# vim hello.py
#!/bin/python
zl = "LULUBAO"
print zl
[root@localhost ~]# python hello.py ##直接用解释器运行程序
LULUBAO
[root@localhost ~]# chmod +x hello.py ##给脚本加执行权限
[root@localhost ~]# ./hello.py ##用绝对路径执行程序
LULUBAO
#!/bin/python
##coding:utf-8 ##注释编码格式
'''
• #coding:utf-8
• #coding=utf-8
• #encoding:utf-8
• #encoding=utf-8
都是可解释中文的编码格式
'''
zl = "璐璐"
print zl
#注释一行
'''
注释一段
'''
"""
注释一段
"""
[root@localhost ~]# ./hello.py
璐璐
五. pyhon解释器
- cpython ##c语言编写的解释器
- ipython ##增强型交互式解释器 可补齐
- pypy
- jython
- IronPython: .Net
六..安装ipython
七. pycharm
IDE工具
1)安装pycharm
[root@localhost pycharm]# tar xf pycharm-community-[root@localhost pycharm]# tar xf pycharm-community-2017.1.4.tar.gz -C /opt/
[root@localhost pycharm]# cd /opt ##第三方软件目录
[root@localhost opt]# ls
pycharm-community-2017.1.4 rh
[root@localhost opt]# mv pycharm-community-2017.1.4 pycharm
[root@localhost opt]# ls
pycharm rh
[root@localhost opt]# cd pycharm/
[root@localhost pycharm]# ls
bin help Install-Linux-tar.txt lib plugins
build.txt helpers jre64 license
[root@localhost pycharm]# vim Install-Linux-tar.txt
[root@localhost pycharm]# ls
bin help Install-Linux-tar.txt lib plugins
build.txt helpers jre64 license
[root@localhost pycharm]# cd bin/
[root@localhost bin]# ls
format.sh idea.properties pycharm64.vmoptions restart.py
fsnotifier inspect.sh pycharm.png
fsnotifier64 log.xml pycharm.sh
fsnotifier-arm printenv.py pycharm.vmoptions
[root@localhost bin]# ./pycharm.sh
2)使用
alt+F12 ##唤出终端
ctrl+alt+s ##唤出setting
3)设置
风格设置;
字体设置;
模板设置;
#!/bin/python
#coding:utf-8
'''
@NAME:${NAME}.py
@DATE:${DATE}
@AUTHOR:LULUBAO
@CONNECT:1214396365@qq.com
@DESC: