# 课程使用python 2.7,IDE使用pycharm
视频教程:牛客网(点击打开链接)
参考教程:菜鸟教程(点击打开链接)
第一节:开发工具和Python语言介绍
主要介绍这个项目需要用到的开发工具,并会帮助简单回顾这个项目所用到的语言-python。
┏━━━━━━━━━━━━━━目录━━━━━━━━━━━━━━┓
1、版本控制系统2、 安装第三方库的方法
【举例】Beautifulsoup——解析Html的库
3、python手册
4、pycharm中的一些快捷键
5、字符串
6、运算操作符 operation
7、内置函数 buildinfunction
8、控制流 controlflow
9、数据结构——列表list、元组tuple、字典dictionary、集合set
10、面向对象——封装、继承、多态
11、异常处理
12、随机数
13、正则表达式
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1、版本控制系统
(1)Git分布式版本控制系统:GitHub/BitBucket
(2)SVN
【来自百度百科:SVN(Subversion)开放源代码的版本控制系统相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。互联网上很多版本控制服务已从CVS迁移到Subversion。说得简单一点SVN就是用于多个人共同开发同一个项目,共用资源的目的。】
2、 安装第三方库的方法
(1)pip install xxx
(2)在pycharm中安装(settings—project—project interpreter)
【举例】Beautifulsoup——解析Html的库
例:爬取糗百的文本
import requests
from bs4 import BeautifulSoup
content = requests.get("http://www.qiushibaike.com").content # get网页
soup = BeautifulSoup(content, "html.parser") # 网页放入beautifulsoup解析
for div in soup.find_all("div", {"class": "content"}): # 打印content内容
print div.text.strip(), "\n"
3、python手册
在安装python的目录中可以找到。(我安装在了D盘,位置为D:\Python27\Doc\python2713.chm)
4、pycharm中的一些快捷键
(1)Ctrl + / 行注释/取消行注释
(2)Ctrl + Alt + L 代码格式化
(3)Tab + Tab 缩进当前行 / Shift + Tab 不缩进当前行
5、字符串
(1)capitalize() 首字母大写
(2)replace() 替换
stra = 'HELLO world'
print stra.capitalize() # (1)首字母大写
print stra.replace('world','haha') # (2)替换
输出
Hello world
HELLO haha
(3)lstrip() / rstrio() 去除开头/末尾的字符串 (缺省为空格字符)
strb = ' \n\rhello world \r\n'
print 1,strb
print 2,strb.lstrip() # 去除开头的指定字符串(缺省为空格字符)
strb2 = " this is example!!! "
print 3,strb2.lstrip() # 同上
strb3 = "888118this is example!!!8888"
print 4,strb3
print 5,strb3.lstrip('8') # 去除开头的8
print 6,strb3.rstrip('8') # 去除末尾的8
输出:
1
hello world
2 hello world
3 this is example!!!
4 888118this is example!!!8888
5 118this is example!!!8888
6 888118this is example!!!
(4) 其他一些字符串的操作与函数
3)startswith() 判断开头
4)endswith() 判断末尾
5)字符串拼接
6)len()
7)join() 字符串之间以指定字符连接(list→string)
8)split() 字符串通过某字符分开(string→list)
9、10)find() 查找指定字符串片段的位置
stra = 'aaa'
strb = 'bbbb'
strc = 'hello world'
print 3, strc.startswith('hel') # 判断字符串是不是以hel开头,输出True
print 4, strc.endswith('x') # 判断字符串是不是以x结尾,输出False
print 5, stra + strb + strc # 字符串拼接,输出aaabbbbhello world
print 6, len(strc) # 字符串长度,输出11
print 7, '-'.join(['a', 'b', 'c']) # 把字符串之间以-连接,输出a-b-c
print 8, strc.split(' ') # 把字符串通过某字符分开为list,输出['hello', 'world']
print 9, strc.find('hello') # 查找指定字符串位置,输出0(字符串‘hello’从位置0开始)
print 10, strc.find('ello') # 输出1(字符串‘ello’从位置1开始)
输出
3 True
4 False
5 aaabbbbhello world
6 11
7 a-b-c
8 ['hello', 'world']
9 0
6、运算操作符 operation
print 1, 1 + 2, 5 / 2, 5 * 2, 5 - 2
print 2, True, not True # not True 输出 False
print 3, 1 < 2, 5 > 2 # 输出 True True
print 4, 2 << 3 # 移位,输出16
print 5, 5 | 3, 5 & 3, 5 ^ 3 # 或,与,异或(位操作,二进制)输出 7 1 6
输出
1 3 2 10 3
2 True False
3 True True
4 16
5 7 1 6
7、内置函数 buildinfunction
【详见使用