网站二次开发合同网站建设项目招标书
- 作者: 五速梦信息网
- 时间: 2026年04月20日 08:09
当前位置: 首页 > news >正文
网站二次开发合同,网站建设项目招标书,react网站开发介绍,怎么增加网站的外链【没有所谓的运气#x1f36c;#xff0c;只有绝对的努力✊】 目录 1、函数 1.1 函数传参中的拆包 1.2 匿名函数的定义 1.3 匿名函数练习 1.4 匿名函数应用——列表中的字典排序 2、面向对象 OOP 2.1 面向对象介绍 2.2 类和对象 2.3 类的构成和设计 2.4 面向对象代码… 【没有所谓的运气只有绝对的努力✊】 目录 1、函数 1.1 函数传参中的拆包 1.2 匿名函数的定义 1.3 匿名函数练习 1.4 匿名函数应用——列表中的字典排序 2、面向对象 OOP 2.1 面向对象介绍 2.2 类和对象 2.3 类的构成和设计 2.4 面向对象代码的步骤 2.5 面向对象——小案例 2.6 self 2.7 对象的属性操作 2.7.1 类外部添加 2.8 魔法方法 2.8.1 init 的使用 2.8.2 str 的使用 2.8.3 del 的使用 3、案例1——小明爱跑步 4、小结 5、作业 5.1 定义一个学生类 5.2 定义一个电脑 6、封装案例——存放家具 7、案例——登录页面用于后续的自动化测试学习 8、私有 和 公有 9、继承 9.1 继承定义 9.2 案例——继承 10、重写 11、多态 12、属性和方法 12.1 属性的划分 12.2 练习 12.3 方法的划分 12.3.1 案例——游戏类 12.4 补充概念——哈希、is 13、小结 14、文件 14.1 文件介绍 14.2 打开文件、读-写文件、关闭文件 14.3 文件——案例 14.3.1 写入文件 14.3.2 读文件 14.4 使用with open打开文件 14.5 按行读取文件内容 14.6 json文件的处理 14.6.1 json文件的语法 14.6.2 json 练习1 14.6.3 json 练习2 14.7 json写入 15、异常 15.1 异常的定义 15.2【捕获所有的异常】 15.3【捕获指定异常】 15.4 【捕获多个指定类型的异常】 15.5 【异常捕获的完整版本】 15.6 异常传递 16、小结 17、模块和包 17.1 模块的导入 17.2 模块的查找顺序 18、name的作用 18.1 练习 19、包 1、函数 1.1 函数传参中的拆包 想要将列表作为参数传入函数中。 》 my_sum( *my_list ) 即可。 想要将字典作为参数传入函数中。 》 my_sum( **my_list ) 即可。 1.2 匿名函数的定义 1.3 匿名函数练习
定义一个匿名函数可以求两个数的乘积。
func1 lambda a,b:a*b print(func1(20,8))# 定义一个匿名函数参数为字典返回字典中键为age的值。 func2 lambda a:a[age] dic {name: 小明, age: 18} print(func2(dic))1.4 匿名函数应用——列表中的字典排序 my_list [{name: 小明, age: 18},{name: 小李, age: 12},{name: 小王, age: 28}] my_list.sort(keylambda x:x[age]) print(my_list)
[{name: 小李, age: 12}, {name: 小明, age: 18}, {name: 小王, age: 28}] 字符串比大小是根据ASCII比较的。 AZaz
ord( 字符 ) 获取字符 的ASCII值。 chr( ASCII值 ) 获取对应的 字符。 2、面向对象 OOP 2.1 面向对象介绍 2.2 类和对象 2.3 类的构成和设计 2.4 面向对象代码的步骤 2.5 面向对象——小案例 需求小猫爱吃鱼小猫要喝水class Cat:def eat(self):print(爱吃鱼)def drink(self):print(爱喝水)cat Cat() cat.eat() 2.6 self 2.7 对象的属性操作 2.7.1 类外部添加 2.8 魔法方法 2.8.1 init 的使用 类名 创建对象。 需求小猫爱吃鱼小猫要喝水class Cat:def init(self,name,age):self.name nameself.age agedef getInfo(self):print(f小猫的名字{self.name},年龄:{self.age})blue_cat Cat(蓝猫,2) blue_cat.getInfo()print(-*30)black_cat Cat(黑猫,3) black_cat.getInfo()2.8.2 str 的使用 需求小猫爱吃鱼小猫要喝水class Cat:def init(self,name,age):self.name nameself.age agedef getInfo(self):print(f小猫的名字{self.name},年龄:{self.age})def str(self):return f{self.name}—-{self.age}blue_cat Cat(蓝猫,2) print(blue_cat)print(-*30)black_cat Cat(黑猫,3) print(black_cat) 2.8.3 del 的使用 3、案例1——小明爱跑步 class Person:def init(self,name,weight):self.name nameself.weight weightdef str(self):return f姓名{self.name}—–体重:{self.weight}def run(self):print(f{self.name}—-跑步)self.weight - 0.5def eat(self):print(f{self.name}—-吃完后)self.weight 1person Person(小明,75) print(person) # 姓名小明—–体重:75person.run() print(person) # 姓名小明—–体重:74.5person.eat() print(person) # 姓名小明—–体重:75.54、小结 5、作业 5.1 定义一个学生类 class Student:def init(self, name, age):self.name nameself.age agedef str(self):return f姓名{self.name}, 年龄{self.age}def eat(self):print(f{self.name} 要吃饭)def sleep(self):print(f{self.name} 要睡觉)def addAge(self):print(过了一个年)self.age 1xm Student(小明,18) xm.eat() xm.sleep() xm.addAge() print(xm)print(-*30) xh Student(小红,17) xh.eat() xh.sleep() xh.addAge() print(xh)5.2 定义一个电脑 class Computer:def init(self,brand,price):self.brand brandself.price pricedef playMovie(self,movie_name):print(f{self.brand} 电脑播放 {movie_name})xm Computer(小米,10000) xm.playMovie(葫芦娃)apple Computer(苹果,16999) apple.playMovie(变形金刚)6、封装案例——存放家具 # 房子类 class House:def init(self, name, total_area):self.name name # 户型self.total_area total_area # 总面积self.free_area total_area # 剩余面积self.item_list [] # 家具名称列表def str(self):return f户型{self.name}—总面积{self.total_area}—-剩余面积{self.free_area}—家具名称{self.item_list}def add_item(self,item): # item 家具对象if self.free_area item.area:self.item_list.append(item.name)self.free_area self.total_area - item.areaprint(f{item.name} 添加成功)else:print(房间不足以放家具)# 家具类 class HouseItem:def init(self,name,area):self.name nameself.area areadef str(self):return f{self.name} —占地面积(平方米):{self.area}bed HouseItem(席梦思,4) chest HouseItem(衣柜,2) table HouseItem(餐桌,1.5) print(bed) print(chest) print(table)print(-*30)house House(三室,109) house.add_item(bed) house.add_item(chest) print(house)7、案例——登录页面用于后续的自动化测试学习 class LoginPage:def init(self,username,password,code):self.username usernameself.password passwordself.code codeself.btn 登录def login(self):print(f1、输入用户名: {self.username})print(f2、输入密码: {self.password})print(f3、输入验证码: {self.code})print(f4、点击按钮: {self.btn})loginPage LoginPage(admin,112345,12hf) loginPage.login() 8、私有 和 公有 9、继承 9.1 继承定义 9.2 案例——继承 class Animals:def eat(self):print(f在吃)class Dog(Animals):def jiao(self):print(叫)class Quan(Dog):pass# animals Animals()
animals.eat()
dog Dog() dog.eat() dog.jiao() print(-*30) quan Quan() quan.eat() quan.jiao() 10、重写 class Dog:def bark(self):print(汪汪汪叫)class Quan(Dog):def bark(self): # 重写父类的bark()方法print(嗷嗷叫)quan Quan() quan.bark() class Dog:def bark(self):print(汪汪汪叫)class Quan(Dog):def bark(self): # 重写父类的bark()方法print(嗷嗷叫)super().bark()print(嗷嗷叫)quan Quan() quan.bark() 11、多态 12、属性和方法 12.1 属性的划分 12.2 练习 class Dog:my_count 0 # 定义类属性def init(self,name): # 定义实例属性init方法中self.name name# 每创建一个对象就会调用init方法Dog.my_count 1dog Dog(小花) dog Dog(斑点狗) print(Dog.my_count) # 2 一般用 类名.属性名 调用。12.3 方法的划分 12.3.1 案例——游戏类 import randomclass Game:# 类属性top_score 0 # 记录游戏的最高分def init(self, name):self.name namedef show_help(self):print(这是游戏的帮助信息)def show_top_score(self):print(f游戏的最高分: {Game.top_score})def start_game(self):random_num random.randint(10, 100) # 生成随机数10-100 (本次游戏得分)print(f本次游戏得分—– {random_num})if random_num Game.top_score:Game.top_score random_numgame Game(小王) game.start_game() game.show_top_score()print(-*30) game.start_game() game.show_top_score() game.show_help()【优化代码】 12.4 补充概念——哈希、is 13、小结 14、文件 14.1 文件介绍 14.2 打开文件、读-写文件、关闭文件 14.3 文件——案例 14.3.1 写入文件 # 1、打开文件 f open(a.txt,modew,encodingutf-8)# 2、写入文件 f.write(偷得浮生半日)# 3、关闭文件 f.close()14.3.2 读文件 # 1、打开文件 f open(a.txt, r,encodingutf-8)
2、读文件
buff f.read() print(buff)
3、关闭文件
f.close() 14.4 使用with open打开文件 with open(a.txt, a, encodingutf-8) as f:f.write(\n窗前明月光\n)f.write(\n疑是地上霜\n) 14.5 按行读取文件内容 # with open(b.txt,encodingutf-8) as f:
while True:
buff f.readline()
if buff 0:
break
else:
print(buff, end)with open(b.txt,r, encodingutf-8) as f:for i in f:print(i,end)
14.6 json文件的处理 14.6.1 json文件的语法 【json文件】 {name: 小明,age: 18,isMen: true,like: [听歌,游戏,购物,吃饭,睡觉,打豆豆],address: {country: 中国,city: 上海} } import jsonwith open(info.json,r,encodingutf-8) as f:result json.load(f)print(result)print(result[name])print(result[address][city]) 14.6.2 json 练习1 [{name: 小明,age: 18,isMen: true,like: [听歌,游戏,购物,吃饭,睡觉,打豆豆],address: {country: 中国,city: 上海}},{name: 小红,age: 17,isMen: false,like: [听歌,学习,购物],address: {country: 中国,city: 北京}} ] import jsonwith open(info1.json,r,encodingutf-8) as f:f_list json.load(f)for i in f_list:print(i[name], i[age], i[address][city])14.6.3 json 练习2 import json newList [] with open(login.json,r,encodingutf-8) as f:info_list json.load(f)for item in info_list:newList.append((item[username],item[password],item[expect]))print(newList)
[(admin, 123456, 登录成功), (root, 123456, 登录失败), (admin, 1234567, 登录失败)]14.7 json写入 import jsonlist_json [(admin, 123456, 登录成功), (root, 123456, 登录失败), (admin, 1234567, 登录失败)]
with open(info4.json,w,encodingutf-8) as f:# json.dump(list_json,f)# json.dump(list_json, f,ensure_asciiFalse) # 显示中文json.dump(list_json,f,ensure_asciiFalse, indent2) # 显示缩进 15、异常 15.1 异常的定义 15.2【捕获所有的异常】 try:num input(请输入数字)num int(num)print(num, num) except:print(异常请输入数字) 15.3【捕获指定异常】 try:num input(请输入数字)num int(num)print(num, 10/num) except ValueError:print(异常请输入数字) 15.4 【捕获多个指定类型的异常】 try:num input(请输入数字)num int(num)print(num, 10/num) except ValueError:print(异常请输入数字) except ZeroDivisionError:print(除数不能为0)15.5 【异常捕获的完整版本】 【常用下方的代码】 15.6 异常传递 16、小结 17、模块和包 17.1 模块的导入 快捷导入包 17.2 模块的查找顺序 18、name的作用 18.1 练习 19、包 今天暂时到这里啦~
- 上一篇: 网站二次开发多少钱微信运营模式
- 下一篇: 网站二级目录怎么做长沙房产交易中心官网
相关文章
-
网站二次开发多少钱微信运营模式
网站二次开发多少钱微信运营模式
- 技术栈
- 2026年04月20日
-
网站恶意镜像专业电子网站建设
网站恶意镜像专业电子网站建设
- 技术栈
- 2026年04月20日
-
网站恶意点击软件厦门35网站建设公司
网站恶意点击软件厦门35网站建设公司
- 技术栈
- 2026年04月20日
-
网站二级目录怎么做长沙房产交易中心官网
网站二级目录怎么做长沙房产交易中心官网
- 技术栈
- 2026年04月20日
-
网站发布方式有哪些青岛网站商城设计
网站发布方式有哪些青岛网站商城设计
- 技术栈
- 2026年04月20日
-
网站发布时间更改wordpress主题压缩包安装提示无效
网站发布时间更改wordpress主题压缩包安装提示无效
- 技术栈
- 2026年04月20日






