![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python学习
Learning_is_endless
天道酬勤 功到自成
展开
-
Python基础(list,tuple,dict,set)
一:list的创建及使用1:list的创建及访问:#list的创建及访问:#(1)正/倒序访问names = ['Bob','Tracy','Eric']print(names) #输出结果:['Bob', 'Tracy', 'Eric']print(names[1]) #输出结果:Tracyprint(names[-1]) #输出结果:Eric,即倒数第一个#(2)多...原创 2019-02-19 16:34:02 · 158 阅读 · 0 评论 -
Python-模块
1:推荐的导入包的形式import TemperatureConversion as tc print("32摄氏度 = %.2f华氏度" % tc.c2f(32))print("99华氏度 = %.2f摄氏度" % tc.f2c(99)) 2:if __name__ == "__main__"def c2f(cel): fah = cel*1.8+32 retur...原创 2019-02-19 16:36:05 · 105 阅读 · 0 评论 -
Python基础-图形界面GUI
第一个图形界面程序:import easygui as gimport syswhile 1: g.msgbox("嗨,欢迎进入第一个界面小游戏^_^") msg ="请问你希望在鱼C工作室学习到什么知识呢?" title = "小游戏互动" choices = ["谈恋爱", "编程","琴棋书画"]原创 2019-02-19 16:35:27 · 941 阅读 · 1 评论 -
Python-爬虫
一个例子:import urllib.requestresponse = urllib.request.urlopen("http://www.baidu.com")html = response.read()print(html) #得出的是二进制代码,输出很乱html = html.decode("utf-8")print(html) #这样就能看到整齐的输出 ...原创 2019-02-19 16:36:59 · 231 阅读 · 0 评论 -
Pyhton魔法方法
魔法方法:一:算术运算#问题写法:class Try_int(int): def __add__(self, other): return self+other def __sub__(self, other): return self-othera = Try_int(3) #这样会出现无限递归的问题b = T...原创 2019-02-19 16:35:57 · 122 阅读 · 0 评论 -
Python3的pip安装以及requests的导入
在学习python爬虫的过程中需要用到requests模块,但是我安装的版本中不自带pip以及requests,因此需要下载导入pip下载地址:https://pypi.org/project/pip/#files(下载下面箭头指向的版本,我直接下载到的桌面)然后进行以下步骤:通过pip list查看是否安装成功如果安装不成功,出现那么可能是因为没有添加环境变量...原创 2019-02-19 16:36:19 · 5485 阅读 · 1 评论 -
Python爬虫-Scrapy框架
安装Scrapy框架:先安装lxml:安装pyOpenSSL:安装Scrapy:(其他方法:https://blog.csdn.net/lucky404/article/details/79422245)开始时出现了异常:ERROR:command "python setup.py egg_info" failed with error code 1 in ......原创 2019-02-19 16:37:22 · 179 阅读 · 0 评论 -
Python基础-正则表达式
正则表达式使用说明:import reprint(re.search(r'FishC','I love FishC.com!'))#输出结果:<re.Match object; span=(7, 12), match='FishC'>#表示在7-12的位置发现了要找的字串print(re.search(r'\d\d\d\.\d\d\d\.\d\d\d\.\d\d\d',...原创 2019-02-19 16:36:30 · 121 阅读 · 0 评论 -
Python基础-递归
非递归方式求阶乘:def factorial(n): result = n for i in range(1,n): result *=i return resultnumber = int(input("请输入一个整数:"))print(factorial(number))递归方式求阶乘:def factorial(n): i...原创 2019-02-19 16:35:35 · 139 阅读 · 0 评论 -
Python基础-global、nonlocal用法、lambda表达式、filter()、map()
1:global将局部变量强制声明为全局变量:def Fun(): count = 10 print(count)Fun() #10print(count) #NameError: name 'count' is not defined, # count是局部变量,只能在定义的函数中查看def Fun(): global cou...原创 2019-02-19 16:33:29 · 294 阅读 · 0 评论 -
Python基础—流程控制语句
一:判断if语句首先要注意的是:python代码的缩进规则缩进:4个空格,不要使用Tab、不要混合Tab和空格(1)if语句age = 20if age>=18: print('your age is',age) print('adult')print('END')(2)if-else语句age = 16if age>=18: ...原创 2019-02-19 16:33:03 · 166 阅读 · 0 评论 -
Python基础—函数
函数的创建及使用(注意全局变量)#(1)定义函数def add2num(a,b): c = a+b print(c)add2num(11,22)#(2)全局变量声明x = 3def selfAdd(a): global x #全局变量的声明 x += 3 a += a print(a,x)a_int = xselfAdd(a_...原创 2019-02-19 16:33:18 · 177 阅读 · 0 评论 -
Python面向对象编程
一:类的组成:1:类的名称:类名2:类的属性:一组数据3:类的方法:允许进行操作的方法(行为) 二:定义类:#定义类(经典类)class Car: #方法: def getCarinfo(self): print("车轮个数:%d,颜色%s"%(self.whelelNum,self.color)) def move(self):...原创 2019-02-19 16:35:48 · 110 阅读 · 0 评论 -
Python基础-文件、模块、pickle、weather forecast
读写文件: f = open('E:\\abc.txt')print(f) #输出:<_io.TextIOWrapper name='E:\\abc.txt' mode='r' encoding='cp936'> f.close() 使用完文件最好要关闭读:f = open('E:\\abc.txt')print(f.read()) ...原创 2019-02-19 16:34:32 · 367 阅读 · 0 评论 -
Python基础-数据类型及运算符
python的基础部分与C语言相似,再这里只记录一下需要注意的地方 一:数据类型:1:int:不计长度,可用于存储计算大数2:e计法15e10 == 15的十次方15e-10 == 15的负十五次方3:浮点数变整数:直接舍掉小数部分4:判断数据类型方法1:type(5.21) 输出:float方法2:isinstance(a,b) 如果a是b类型,返回T...原创 2019-02-19 16:35:40 · 165 阅读 · 0 评论 -
Python基础-标准异常、异常处理
Python标准异常总结f = open('asdf.txt') #我电脑中并没有这个文本print(f.read())f.close()由于不存在这个文本,所以会返回异常: 检测异常:1:try......except......(一旦检测到异常,其他程序就不会再执行)try: f = open('asdf.txt') #我电脑中并没有这个文本 ...原创 2019-02-19 16:34:40 · 143 阅读 · 0 评论 -
Python基础-else语句拓展、with语句
一:else语句while...else...(只有当while语句执行完毕,才会执行else,若while被break,else语句就不会执行了)def showMaxFactor(num): count = num//2 while count>1: if num % count==0: print('%d的最大约数是:%...原创 2019-02-19 16:34:47 · 147 阅读 · 0 评论 -
steuptools 以及 easygui安装
由于我在直接安装easygui的时候,出现了缺少‘setuptools’的问题,所以需要下载setuptools下载地址:easygui:https://github.com/robertlugg/easyguisetuptools:https://pypi.org/project/setuptools/#files我将下载解压后的easygui和setuptools都放在了桌面...原创 2019-02-19 16:35:09 · 214 阅读 · 0 评论