![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python基础代码
悟空学python
知识就是力量,坚持能坚持的¥@
展开
-
闭包函数
闭包函数的条件:1.内函数调用了外函数的变量2.外函数把内函数返回的过程叫做闭包这个内函数叫闭包函数闭包函数的基本语法闭包函数的特点:1.内部函数调用了外部函数的局部变量2.这个局部变量与内部函数发生绑定3.这个变量的生命周期延长...原创 2020-04-21 00:17:08 · 78 阅读 · 0 评论 -
购物车 (面向过程是实现)
#购物车的功能#客户模块#1.添加商品#2.去除商品#3.展示商品#4.结算#商家模块#1.会员注册#2.会员登陆#2.后台添加商品#商家模块import timeimport pickleimport jsonimport osmypath=os.getcwd()os_name=os.nameprint(os_name)print(type(os_name)...原创 2019-07-08 15:47:45 · 162 阅读 · 0 评论 -
python 生成器读大内存文件
5.读取一个文件所有内容,通过生成器调用一次获取一行数据.#当前读取的行数n,记录从第几行开始读取,默认为0#path读取文件的路径def myread(path,n=0):with open(path,mode=“r”,encoding=“utf-8”)as fp:res = fp.readline()n+=1while res: print("你当前读取的行数行数%s"...原创 2019-06-30 20:47:45 · 389 阅读 · 0 评论 -
bullet
子弹类class Bullet(): def __init__ (self,bullet_count): self.bullet_count=bullet_count #枪类class Gun():def init(self,bullet):self.bullet=bulletdef shoot(self,bullet_num):if sel...原创 2019-07-08 22:00:48 · 206 阅读 · 0 评论 -
python 单例(单态模式)
#创建一个单例的类 class Singleton(object)#同一个类无论实例化多少个对象,其存储地址都是同一块地址,节省内存空间class Singleton():__obj=Nonedef __new__(cls,*args,**kwargs): if cls.__obj is None: cls.__obj=object.__new__(cls) return cls...原创 2019-07-09 20:21:21 · 258 阅读 · 0 评论