Python语言

1.Python语言

1.1 Python语言的基本概念

  1. Python是一门极少数能兼具、简单且功能强大的编程语言,专注于如何解决问题,而不是语法和结构。
  2. 官方的Python介绍:
    Python 是⼀款易于学习且功能强⼤的编程语⾔。 它具有⾼效率的数据结构,能够简单⼜有效地实现⾯向对象编程。Python 简洁的语法与动态输⼊之特性,加之其解释性语⾔的本质,使得它成为⼀种在多种领域与绝⼤多数平台都能进⾏脚本编写与应⽤快速开发⼯作的理想语⾔。
  3. Python的创造者:吉多~范罗苏姆(Guldo van Rossum),名字来源于《蒙提·派森的飞⾏⻢戏团(Monty Python’s Flying Circus,译巨蟒剧团)》

1.2 Python 语言的特色

  1. 简单
  2. 易于学习
  3. 自由且开放
  4. 跨平台
  5. 可嵌入性
  6. 丰富的库

1.3 Python 的发展及应用

  1. 目前排名靠前
  2. Python 的应用
    常规软件的开发
    科学计算
    自动化运维
    自动化测试
    WEB开发
    网络爬虫
    数据分析
    人工智能
  3. The Zen of Python, by Tim Peters
    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren’t special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you’re Dutch.
    Now is better than never.
    Although never is often better than right now.
    If the implementation is hard to explain, it’s a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea – let’s do more of those!

2. 搭建环境

2.1 Python的解释器

  1. Python环境的搭建就是安装Python的解释器
  2. Python的解释器分类:
    CPython:C语言编写的Python解释器(官网所用的版本)
    PyPy:用Python语言的Python解释器
    JPython:用Java编写的Python解释器

2.2 Python环境的搭建

  1. 管网链接:Python官网----https://www.python.org/
  2. 下载安装包
  3. Python 3.7.7rcl,带后缀的安装包不推荐下载,都是临时版本。
  4. embeddable 是嵌入式文件 executable是可执行文件 web-based是联网安装文件。一般选择executable版本下载。
  5. 安装Python时一定要勾选“Add Python 3.7 to PATH”,为了方便Python可以在不同目录下执行
  6. pip一定要勾选
  7. 安装成功后,打开CMD,执行命令python,可以看到目前安装的python的信息,表示安装成功,也可以执行命令python -V或者python --version查看当前Python的版本

2.3 Python的交互模式

  1. win键+R–>CMD–>回车–>输入Python
  2. 命令行结构
  3. Python 3.6.5… -->版本
  4. Type “help”,“copyright”… -->版权声明
  5. “>>>” -->命令提示符(在后面可以直接输入指令)

2.4 pip工具的使用

  1. pip介绍:
    我们都知道python有很多的第三⽅库或者说是模块。这些库针对不同的应⽤,发挥不同的作⽤。我们在实际的项⽬中肯定会⽤到这些模块。那如何将这些模块导⼊到⾃⼰的项⽬中呢?
    Python官⽅的PyPi仓库为我们提供了⼀个统⼀的代码托管仓库,所有的第三⽅库,甚⾄你⾃⼰写的开源模块,都可以发布到这⾥,让全世界的⼈分享下载 。python有两个著名的包管理⼯具easy_install和pip。在python 2中easy_install是默认安装的,⽽pip需要我们⼿动安装。随着Python版本的提高,easy_install已经逐渐被淘汰,但是⼀些⽐较⽼的第三⽅库,在现在仍然只能通过easy_install进⾏安装。⽬前,pip已经成为主流的安装⼯具,⾃Python2 >=2.7.9或者Python 3.4以后默认都安装有pip
  2. pip的使用:
    在命令行下,输入pip,回车可以看到帮助说明(千万不能先输入python在输入pip----否者pip就会当成一个对象处理)
    pip版本查看命令: pip -V pip --version
    普通安装: pip install module
    指定版本安装: pip install module2.8.7
    卸载已安装的库 pip uninstall module
    1 pip uninstall SomePackage
    2 pip uninstall SomePackage
    1.0.5 指定版本卸载
    3 pip uninstall SomePackage>=1.0.5 最小版本卸载
    升级或卸载指定的包,通过使用==,>=,<=,>,<来指定一个版本号
    列出已经安装的库: pip list
    显示安装包的信息: pip show module/package
    pip版本更新: 执行命令 python -m pip install --upgrade pip,若出现报错,可先执行命令python -m ensurepip,查看pip是否安装,然后再执行命令 python -m pip install --upgrade pip 即可更新完毕
    将已经安装的库列表保存到文本文件中: pip freeze > D:\桌面\install.txt
    使用wheel文件安装库: 除了使⽤上⾯的⽅式联⽹进⾏安装外,还可以将安装包也就是wheel格式的⽂件,下载到本地,然后使⽤pip进⾏安装。⽐如我在PYPI上提前下载的pillow库
    的wheel⽂件,后缀名为whl。地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
    第一步:安装wheel: 执行命令----pip install wheel
    第二步:找到下载的whl文件的目录进行安装
    第三步:执行命令安装----pip install yappi-0.98-cp27-cp27-win_and64.whl(whl文件)
    换源安装:
    ⾖瓣 :http://pypi.douban.com/simple/
    阿⾥ :http://mirrors.aliyun.com/pypi/simple/
    中国科学技术⼤学:http://pypi.mirrors.ustc.edu.cn/simple
    清华:https://pypi.tuna.tsinghua.edu.cn/simple
    例如:pip install SomePackage -i http://pypi.douban.com

2.5 Pythong的第一个程序

可以在交互模式实现
可以用Python自带的IDLE实现
可以用高级开发工具如:PyCharm

3. PyCharm的安装和配置

官网: https://www.jetbrains.com/pycharm/
PyCharm的简单配置
1 主题修改:File–settings–apperance–theme
2 代码字体修改:File–settings–Editor-Font
3 关闭更新:File–settings—apperance—System Settings —Updates — Automatically check updates for 取消打钩
4 快捷键修改:File–settings—apperance-- Keymap
5 自动导包:File–settings—apperance–Editor—General —Auto Import 打钩
6 禁止打开上次的工程:File–settings—apperance—System Settings —Reopen last project startup
7 修改文件头:File–settings–Editor—Code Style — File and Code Templates — Python Script
8 修改字体编码:File–settings–Editor—Code Style — File Encoding — Project Encoding

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值