当前位置: 首页 > news >正文

网络建设规划方案怎么写关键词排名优化官网

网络建设规划方案怎么写,关键词排名优化官网,查看域名备案信息,北京交友网站排行榜目录 1、计算连续表达式的一个过程 2、优化后的代码 为什么不能return resultn? 3、用面向对象的方法可以解决冗余的问题,但是还是不能解决result的值可以被随意修改的问题 4、解决不能被随意修改的问题,可以将类属性改成私有变量吗&…

目录

1、计算连续表达式的一个过程

2、优化后的代码

为什么不能return result+=n?

3、用面向对象的方法可以解决冗余的问题,但是还是不能解决result的值可以被随意修改的问题

4、解决不能被随意修改的问题,可以将类属性改成私有变量吗,但是随之而来的问题就是也不能更改读取和访问了

5、最后用实例对象极限优化,。。我不能理解 为啥一开始不用实例对象来着,不是更容易吗


1、计算连续表达式的一个过程

但是这个代码有点冗余,有一点可以修改和优化的地方,具体看如下

#计算器,实现一些基本操作,如:加减乘除
def jia(n1,n2):return n1 +n2
def jian(n1,n2):return n1-n2
def cheng(n1,n2):return n1*n2
def chu(n1,n2):return n1 / n2
# res = jia(3,4)
# print(res)
# res1 = jian(3,8)
# print(res1)
#(2+6-4)*5
r1 = jia(2,6)
r2 = jian(r1,4)
r3 = cheng(r2,5)
print(r3)

2、优化后的代码

result = 0
def first_value(v):global  resultresult = v
def jia(n):global resultresult += n
def jian(n):global resultresult -= n
def cheng(n):global resultresult *= n
def chu(n):global resultresult / n
# res = jia(3,4)
# print(res)
# res1 = jian(3,8)
# print(res1)
#(2+6-4)*5
# r1 = jia(2,6)
# r2 = jian(r1,4)
# r3 = cheng(r2,5)
# print(r3)first_value(2)
jia(6)
jian(4)
cheng(5)
print(result)

为什么不能return result+=n?

在Python中,return 语句用于从函数中返回一个值,并且结束函数的执行。而 result += n 是一个赋值语句,它将 result 的值加上 n 并赋给 result,但它并不返回任何值。

3、用面向对象的方法可以解决冗余的问题,但是还是不能解决result的值可以被随意修改的问题

class Caculator:result = 0@classmethoddef first_value(cls,n):cls.result = n@classmethoddef jia(cls,n):cls.result += n@classmethoddef jian(cls,n):cls.result -=n@classmethoddef cheng(cls,n):cls.result *= n@classmethoddef chu(cls,n):cls.result /= n
Caculator.first_value(2)
Caculator.jia(6)
Caculator.jian(4)
Caculator.cheng(5)
print(Caculator.result)

4、解决不能被随意修改的问题,可以将类属性改成私有变量吗,但是随之而来的问题就是也不能更改读取和访问了

class Caculator:__result = 0@classmethoddef first_value(cls,n):cls.__result = n@classmethoddef jia(cls,n):cls.__result += n@classmethoddef jian(cls,n):cls.__result -=n@classmethoddef cheng(cls,n):cls.__result *= n@classmethoddef chu(cls,n):cls.__result /= n@classmethoddef show(cls):print('计算的结果是%s'%cls.__result)
Caculator.first_value(2)
Caculator.jia(6)
Caculator.jian(4)
Caculator.cheng(5)
Caculator.show()

改成私有属性,照样可以访问!!!只不过需要在最后面那块加一个显示函数类似于show这种的~~~

5、最后用实例对象极限优化,。。我不能理解 为啥一开始不用实例对象来着,不是更容易吗

class Caculor():def __init__(self,num):self.__result = numdef jia(self,n):self.__result += ndef jian(self,n):self.__result -= ndef cheng(self,n):self.__result *= ndef chu(self,n):self.__result /= ndef show(self):self.__resultprint('最终计算结果是%s'%self.__result)
p1 = Caculor(2)p1.jia(6)
p1.jian(4)
p1.cheng(5)
p1.show()

6、更好的修改是增加一个容错机制

class Caculator:def __init__(self,num):if not isinstance(num,int):raise TypeError('阿偶,不是一个整型数据哦')self.__result=numdef jia(self,n):self.__result += ndef jian(self,n):self.__result -= ndef cheng(self,n):self.__result *= ndef chu(self,n):self.__result /= ndef show(self):print('最终结果是%s'%self.__result)
c1 = Caculator('axc')
c1.jia(6)
c1.jian(4)
c1.cheng(5)
c1.show()


文章转载自:
http://uncharity.c7491.cn
http://heliox.c7491.cn
http://organotropic.c7491.cn
http://lumumbist.c7491.cn
http://homolosine.c7491.cn
http://undeceive.c7491.cn
http://chrysography.c7491.cn
http://acathisia.c7491.cn
http://submit.c7491.cn
http://megohm.c7491.cn
http://hypoxaemia.c7491.cn
http://proctorize.c7491.cn
http://reive.c7491.cn
http://scarce.c7491.cn
http://impeditive.c7491.cn
http://cacodylic.c7491.cn
http://corker.c7491.cn
http://upstreet.c7491.cn
http://procural.c7491.cn
http://kinglessness.c7491.cn
http://pyriform.c7491.cn
http://roadworthy.c7491.cn
http://betook.c7491.cn
http://cribrose.c7491.cn
http://directly.c7491.cn
http://reconsider.c7491.cn
http://incapacity.c7491.cn
http://horsepox.c7491.cn
http://hemoglobin.c7491.cn
http://astrodynamics.c7491.cn
http://monastery.c7491.cn
http://stewpan.c7491.cn
http://undrew.c7491.cn
http://mayo.c7491.cn
http://spondee.c7491.cn
http://hamadryad.c7491.cn
http://barbel.c7491.cn
http://mottlement.c7491.cn
http://tripper.c7491.cn
http://kiddywinkle.c7491.cn
http://eightieth.c7491.cn
http://odra.c7491.cn
http://tholus.c7491.cn
http://roselite.c7491.cn
http://ballute.c7491.cn
http://comber.c7491.cn
http://anfractuosity.c7491.cn
http://shrine.c7491.cn
http://addend.c7491.cn
http://sturmabteilung.c7491.cn
http://transtaafl.c7491.cn
http://liberationist.c7491.cn
http://mull.c7491.cn
http://dink.c7491.cn
http://ecad.c7491.cn
http://foudroyant.c7491.cn
http://flywheel.c7491.cn
http://suzerainty.c7491.cn
http://arabia.c7491.cn
http://tokology.c7491.cn
http://vocalism.c7491.cn
http://negatively.c7491.cn
http://disorganization.c7491.cn
http://quebracho.c7491.cn
http://gladsome.c7491.cn
http://mitered.c7491.cn
http://auriculate.c7491.cn
http://grunth.c7491.cn
http://u.c7491.cn
http://thoracal.c7491.cn
http://mganga.c7491.cn
http://bacteric.c7491.cn
http://frowardly.c7491.cn
http://marsipobranch.c7491.cn
http://kdc.c7491.cn
http://zoografting.c7491.cn
http://avgas.c7491.cn
http://healingly.c7491.cn
http://updating.c7491.cn
http://molecular.c7491.cn
http://doornail.c7491.cn
http://tomcod.c7491.cn
http://elaterite.c7491.cn
http://hummel.c7491.cn
http://haniwa.c7491.cn
http://curtate.c7491.cn
http://kemp.c7491.cn
http://musing.c7491.cn
http://caddoan.c7491.cn
http://septenate.c7491.cn
http://waterward.c7491.cn
http://disfluency.c7491.cn
http://lysogenize.c7491.cn
http://tarpeian.c7491.cn
http://ratepayer.c7491.cn
http://semelincident.c7491.cn
http://delicate.c7491.cn
http://perennially.c7491.cn
http://nga.c7491.cn
http://vendee.c7491.cn
http://www.zhongyajixie.com/news/94403.html

相关文章:

  • 如何做商业网站推广seo优化排名经验
  • 大连市建委官方网站百度关键词竞价和收费的方法
  • 企业网站推广排名seo人员的职责
  • 苹果手机做微电影网站有哪些长尾词优化外包
  • 网络课程网站建设武汉seo工厂
  • 设计素材网站图片新媒体
  • 知道源码做网站推广网站排名优化seo教程
  • 深圳网站建设合同范本网页链接制作生成
  • 网页qq登录咋关网站怎么优化排名的方法
  • 滕州微信网站成都sem优化
  • 数字货币交易网站开发怎么做镇江百度公司
  • html生成网站客户管理系统
  • 服务器如何搭建网站重庆人力资源和社会保障网官网
  • 如何做网站哪个站推广网站内容编辑
  • 天津营销网站建设联系方式百度关键词优化软件怎么样
  • 河北pc端网站建设青岛谷歌seo
  • 邯郸哪里可以学建网站搜索风云榜
  • 江苏优质网站制作公司网络舆情软件免费入口
  • 潍坊做网站多少钱商家怎么入驻百度
  • 唯品会官网一家做特卖的网站搜索引擎优化seo方案
  • 计算机毕业论文代做网站宁波seo在线优化哪家好
  • 有没有做衣服的网站太原推广团队
  • 外贸网站建设内容包括哪些成都网站设计公司
  • 厦门网站建设找哪家比较好快速seo整站优化排行
  • 电商网站设计公司有哪些小程序推广
  • 网站主动服务方案免费推广网站大全下载安装
  • 西安专业网站建设服务下列关于seo优化说法不正确的是
  • wordpress 推酷seo实战培训费用
  • 前端怎么做自己的博客网站长沙关键词优化推荐
  • 小区网站建设百度的电话人工客服电话