自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 收藏
  • 关注

原创 《python编程:从入门到实践》9.3继承

class Car(): def __init__(self,make,model,year): self.make = make self.model = model self.year = year self.odometer_reading = 0 def get_descripitive_name(self)...

2020-02-06 10:18:27 170

原创 《python无师自通》第十九章 版本控制

import urllib.requestfrom bs4 import BeautifulSoupclass Scraper: def __init__(self, site): self.site = site def scrape(self): r = urllib.request.urlopen(s...

2020-01-23 11:26:38 131

原创 《python无师自通》第十八章 包管理器

安装框架C:\Users\Administrator>cd C:\Users\Administrator\AppData\Local\Programs\Python\Python38\ScriptsC:\Users\Administrator\AppData\Local\Programs\Python\Python38\Scripts>pip.exe install bottle...

2020-01-21 15:50:39 135

原创 《python无师自通》第十七章 正则表达式

简单匹配import rel = "beautiful is better than uqly."matches = re.findall("beautiful",l)print(matches)['beautiful']import rel = "beautiful is better than uqly."matches = re.findall("Beautiful...

2020-01-20 13:26:02 208

原创 《python无师自通》第十五章 综合练习

战争from random import shuffle#卡牌class Card: suits = ["spades",#表示花色 "hearts", "diamonds", "clubs"] values = [None,None,"2","3",#两个空值是为了数字2对应索引2...

2020-01-18 09:59:05 319

原创 《python无师自通》第十四章 深入面向对象编程

视代码如诗词,勿要做无所谓的堆砌class Rectangle(): recs = []#类变量 def __init__(self,w,l): self.width = w#实例变量 self.length = l self.recs.append((self.width, ...

2020-01-15 10:49:05 302

原创 《python无师自通》第十三章 面向对象编程的四大支柱

抽象多态继承方法继承class Shape(): def __init__(self,w,l): self.width = w self.length = l def print_size(self): print("""{} by {} """.format(self.width, ...

2020-01-14 15:13:16 424

原创 《python无师自通》第十二章 编程范式

面向对象编程类classclass Orange: def __init__(self,w,c): self.weight = w self.color = c print("Created!")orl = Orange(10,"dark orange")print(orl.color)print(orl.weight)cla...

2020-01-14 09:50:51 291

原创 《python无师自通》第十章 综合练习hangman

本章将结合目前所学的知识,开发一个文本游戏—经典的 Hangman 猜词游戏。如 果之前没玩过,可先了解游戏的大致规则。1.玩家一挑选一个秘密单词,单词中有多少个字母,则划多少条横线(这里用下划线表示)。2.玩家二每次猜一个字母。3.如果玩家二猜测的字母正确,玩家一将下划线修改为正确的字母。在本书的游戏版本中,如果单词中有一个字母出现两次,玩家二也必须猜两次。如果玩家二猜测错误,玩家一...

2020-01-13 15:36:28 432

原创 《python无师自通》第九章 文件

读写文件st = open("pythontest.txt","w+")#可读可写模式st.write("hi from python")st.close()#一定要关闭如果一直忘记关闭文件,那就试一下这个方法with open("pythontest.txt","w+") as f: f.write("yes")#会把之前的内容覆盖掉读取文件with open("p...

2020-01-11 16:44:15 236

原创 《python无师自通》第八章 模块

导入模块import mathprint(math.pow(2,3))import randomprint(random.randint(0,100))import statisticsnums = [1,5,3,6,4,5]print(statistics.mean(nums))检查是不是模块>>> import keyword>&...

2020-01-11 11:14:09 239

原创 《python无师自通》第七章

for循环name = "TED"for i in name : print(i)tv = ["got","jfa","sff"]i = 0for show in tv: new = tv[i]#元组要使用中括号 new = new.upper() tv[i] = new i += 1print(tv)range函数for i in ...

2020-01-11 10:10:01 264

原创 《python无师自通》第六章

格式化大括号可以替换成其他>>> "willian {}".format("good")'willian good'n1 = input("请输入名词:")v = input("请输入动词:")adj = input("请输入形容词:")adv = input("请输入副词:")r = """这个{}{}到{}还有{} """.format(n1,v,...

2020-01-10 15:10:47 489

原创 《python无师自通》第五章

方法>>> "hello".upper()'HELLO'>>> "hello".replace("e","**")'h**llo'>>> pool = list()>>> pool[]>>> pool = ["fish","turtle","water"]>>> po...

2020-01-09 15:15:16 363

原创 《python无师自通》第四章

定义defdef f(x): return x * 2#return一定要有result = f(2)print(result)内置函数BIFdef even_odd(): n = int(input("请输入一个整数:")) if n % 2 == 0: print("他是偶数") else : print("他是奇...

2020-01-09 10:39:13 478

原创 《python无师自通》第三章

1.请打印 3 个不同的字符串。print("31")print("ajf")print("盎司附近")31ajf盎司附近2.编写程序:如果变量的值小于 10,打印一条消息;如果大于或等于 10,则打印不同的消息。a = int(input("请输入一个整数:"))if a <10 : print("一条消息")else : print("这是不同的...

2020-01-08 11:24:49 398 1

原创 039类和对象:拾遗

组合class Turtle: def __init__(self,x): self.num = xclass Fish: def __init__(self,x): self.num = xclass Pool: def __init__(self,x,y): self.turtle = Turtle(x)#实例化...

2020-01-07 17:18:21 150

原创 038类和对象:继承

父类:被继承的类子类:继承的类>>> class parent: def hello(self): print("正在调用父类的方法") >>> class child(parent): pass>>> p = parent()>>> p.hello()正在调用父类的方法>>> ...

2020-01-07 11:18:29 85

原创 037类和对象:面向对象编程

self是什么?相当于每个房子的编号>>> class ball: def setname(self,name): self.name = name def kick(self): print("我是%s,该死的,谁砸我。。。" % self.name) >>> a = ball()>>> b = ball()&gt...

2020-01-06 16:47:39 109

原创 036类和对象:给大家介绍对象

对象= 属性+方法创建一个实例对象class Turtle:#Python中的类名约定以大写字母开头 """关于类的一个简单例子""" #属性 color = "green" weight = 10 legs = 4 shell = True mouth = "大嘴" #方法 def climb(self): ...

2020-01-06 16:02:35 124

原创 034丰富的else语句和简洁的with语句

求最大公约数def showMaxFactor(num): count = num // 2 while count > 1: if num % count == 0: print("%d最大的约数%d" % (num,count)) break#如果弹出break弹出,后面的内容不再执行 co...

2020-01-04 17:11:42 197

原创 032异常处理:你不可能总是对的

python标准异常总结try-except语句(检测异常,后面的程序不运行)try: f = open("我不是文件.txt") print(f.read()) f.close()except OSError as reason: print("文件出错啦!错误原因是:" + str(reason))try-finally语句(检测异常,后面的程序继续...

2020-01-03 15:47:40 390

原创 031永久储存:腌制一缸美味的泡菜

pickle模块>>> my_list = [123,456,"按时交付",["another list"]]>>> pickle_file = open('my_list.pkl','wb')#创建一个文件>>> pickle.dump(my_list,pickle_file)>>> pickle_file.clos...

2020-01-03 14:50:47 111

原创 030文件系统:介绍一个高大上的东西OS

先引用再调用>>> import random>>> secret = random.randint(1,10)>>> secret4

2020-01-03 14:28:24 205

原创 029文件:一个任务

一篇文章按照======分割成三段f = open("C:\\Users\\Administrator\\Desktop\\新建文本文档.txt")boy = []girl = []count = 1for each_line in f: if each_line[:6] != "======": (role,line_spoken) = each_line....

2020-01-03 13:31:58 196

原创 028文件:因为懂你,所以永恒

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200102153654264.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMTY5NTE2,size_16,color_FFFFFF,t...

2020-01-02 16:35:26 174

原创 027集合:在我的世界里,你就是唯一

>>> num = {1,2,3}>>> type(num)<class 'set'>>>> num2 = {1,2,3,4,5,5,4,2,1}>>> num2{1, 2, 3, 4, 5}set()>>> set1 = set([1,2,3])>>> se...

2020-01-02 15:33:05 99

原创 025字典:当索引不好用时

fromkeys()方法语法: dict.fromkeys(seq[, value])>>> dict1.fromkeys((1,2,3),("one","two","three")){1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}dict1 = dic...

2020-01-02 15:18:47 157

原创 024递归:汉诺塔

汉诺塔def hanoi(n,x,y,z): if n == 1: print(x,"-->",z) else: hanoi(n-1,x,z,y)#将前n-1个盘子从想移动到y上 print(x,"-->",y)#将最底下的最后一个盘子从x移动到z上 hanoi(n-1,y,x,z)#将y上的n-1个盘子...

2019-12-31 16:11:49 142

原创 023递归:这帮小兔崽子

斐波那契数列20个月后总数量迭代实现方式def fab(n): n1 = 1 n2 = 1 n3 = 1 if n<1: print("输入有误") return -1 while (n-2)>0: n3 = n2 + n1 n1 = n2 n2 = n3 ...

2019-12-31 14:45:33 133

原创 022函数:递归是神马

递归是什么?函数调用自身汉诺塔游戏树结构的定义谢尔宾斯基三角形女神自拍求阶乘的函数def factorial(n): if n == 1: return 1 else: return n * factorial(n-1)number = int(input("请输入一个正整数:"))result = factorial(numbe...

2019-12-30 15:55:43 124

原创 021函数:lambda表达式

lambda函数就不用给函数起名字>>> fun1()25>>> def ds(x): return 2* x + 1>>> ds(5)11>>> g = lambda x : 2 * x + 1>>> g(5)11filter()过滤器>>> list(filt...

2019-12-27 16:09:45 209

原创 020函数:内嵌函数和闭包

global 全局变量>>> def myfun(): global count count = 10 print(10) >>> myfun()10>>> count10>>> 内嵌函数>>> def fun1(): print("fun1正在被调用") def fun2...

2019-12-26 09:23:17 190

原创 019函数:我的地盘听我的

def discounts(price,rate): final_price = price * rate #print("这里试图打印全局变量old_price的值:",ald_price) old_price = 50 print("修改后的old_price值是:",old_price) return final_priceold_price = ...

2019-12-23 18:09:17 74

原创 018函数:灵活即强大

关键参数>>> def say(name,words): print(name + ">" + words) >>> say (name = "工程", words = "管理")工程>管理默认参数>>> def say(name = "默认",words = "参数"): print(name + ">...

2019-11-27 11:08:40 125

原创 017函数:乐高积木

定义函数>>> def myfirstfunction(): print("这是我第一个函数") print("我表示很激动") >>> myfirstfunction<function myfirstfunction at 0x0000014FEFD0B4C0>>>> myfirstfunction()这是我第一...

2019-11-25 16:51:17 139

原创 016序列

sorted()sum()reversed()>>> numbers = (1,5,7,646,-56)>>> reversed(numbers)<reversed object at 0x000001D2620DE640>>>> list(reversed(numbers))[-56, 646, 7, 5, 1]...

2019-11-21 15:56:51 115

原创 015字符串:格式化

统一的规格输出,不让驴唇对马嘴format>>> "{0} love {1} {2}".format("i","c","p")'i love c p'>>> "{0:.1f}{1}".format(27.656,"GB"#0.1f定点数去十位小数'27.7GB'字符串格式化>>> "%c %c .%c" % (97,98,99)...

2019-11-20 14:17:02 119

原创 014字符串:各种奇葩的内置方法

capitallize首字母大写>>> str1.capitalize()'I love china'casefold所有字母小写>>> str2 = "ADASF">>> str2.casefold()'adasf'center(width)字符串居中并填充空格到指定长度>>> str2.center(2...

2019-11-20 10:14:09 131

原创 013元组:带上枷锁的列表

元组和列表的不同创建一个元组()>>> tuple = (1,2,3,4,5,6,7,8)>>> tuple[1]2>>> tuple[5:](6, 7, 8)>>> b = (1,2,3)#有小括号有逗号,就可以创建元组>>> type(b)<class 'tuple'>...

2019-11-20 09:25:18 74

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除