牛客 | 初级项目课(python) | 学习笔记01

# 课程使用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

【详见使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值