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

中国建设银行官方网站手机银行网络营销文案实例

中国建设银行官方网站手机银行,网络营销文案实例,织梦 视频网站源码,北京做网站公司推荐目录 前言: 什么是封装 Python私有化封装 习题 前言: 上一期是讲解Python中类的私有属性和方法,其实很好理解,我给一个类中的部分属性进行加密拒绝访问(上一期链接Python进阶-----面向对象2.0&#…

目录

前言:       

什么是封装

Python私有化封装

习题


前言:       

        上一期是讲解Python中类的私有属性和方法,其实很好理解,我给一个类中的部分属性进行加密拒绝访问(上一期链接Python进阶-----面向对象2.0(特有属性和方法与私有属性和方法)_Python欧尼酱的博客-CSDN博客),其实这是一种封装的体现。其实日常生活中有很多事物都是进行过封装处理,比如说一个箱子,里面封装了一些物品;一些个人信息资料,也是进行了加密处理,这些都是封装的体现。当然代码也是可以去封装的,而且封装还是Python面对对象的三大特征之一,下面就一期来看看吧。

什么是封装

        封装是一种编程思想,不仅仅是Python中有的,通过封装我们可以去把一些代码块功能或者数据进行打包处理,这样我们就不需要关系里面具体的代码细节,要用的时候就拿出来用就行了,一个函数也是一种封装体现,我们想用就用,并不会影响代码的整体性。这就是封装的好处

 封装的意义封装的最大好处是提高程序的安全性,提高程序的运作效率

举个例子:当我们去做一个项目的时候,我们会把这个项目的各个功能分开处理,而不是全部放到一起,分开处理的过程其实就是一个封装处理过程,这样使得程序具有高内聚,低耦合的特点,而不是出现牵一发而动全身,使得程序运行更加稳定。

 在Python面向对象中狭义的封装也就是对一个类对一些属性和方法进行封装,或者累中的成员再次进行封装处理,下面先看个例子。

 没有封装处理的代码:

if __name__=='__main__':user_name=input('账号:')password=input('密码:')if user_name=='root' and password=='123456':print('登陆成功!')

进行封装处理的代码:

class User(object):def __init__(self,user_name,password):self.user_name=user_nameself.password=passworddef login(self):if self.user_name=='root' and self.password=='123456':print('登陆成功!')
if __name__=='__main__':u=User('root','123456')User.login(u)

这样对比就很明显了。

Python私有化封装

在Python中定义一些属性的时候,我们要对一些重要的信息进行加密封装处理,也就是进行私有化,外部的实例对象是无法去访问的,而在类的内部是可以去调用的,所以我们可以在类中定义相关方法作为一个验证,当验证通过时才可以去访问相关信息,实例如下: 

class User(object):def __init__(self,user_name,password,test='abcde'):self.user_name=user_nameself.__password=password #密码加密私有化self.__test=test         #验证信息加密def login(self):if self.user_name=='root' and self.__password=='123456':print('登陆成功!')def getpassword(self,test): #建立一个验证信息从而访问密码if test==self.__test:return self.__passwordreturn False
if __name__=='__main__':u=User('root','123456')print(u.user_name)# print(u.__password) 是访问不到了,因为password被私有化了User.login(u)print(u.getpassword('abcde'))
#输出结果:
# root
# 登陆成功!
# 123456

习题


   利用类完成一个简易的计算器
   1、属性为两位参与计算的数字
   2、实现加减乘除的四种计算方法

    1 , 定义一个人类
    2 , 人物属性 : 性别 , 身高 , 体重, 健康度 ...
    3 , 方法1 : 跑步 : 体重减少0.5 , 健康度增加 0.01
    4 , 方法2 : 走路 : 体重减少0.01
    5 , 方法3 : 吃饭 : 体重增加0.8 , 健康度增加 0.05
    6 , 方法4 : 睡懒觉 : 体重增加2, 健康度增加 2

 你们可以去做做看

答案:

#1.计算器
class calc:def __init__(self):print('the result is')def __add(self,num1,num2):return num1+num2def __sub(self,num1,num2):return num1-num2def __mul(self,num1,num2):return num1*num2def __div(self, num1, num2):return num1/num2def computer(self,num1,num2,count):if count=='add':return self.__add(num1,num2)elif count=='sub':return self.__sub(num1,num2)elif count=='mul':return self.__mul(num1,num2)elif count=='div':return self.__div(num1,num2)
# if __name__=='__main__':
#     a=int(input('num1:'))
#     b=int(input('num2:'))
#     count=input('count:')
#     com=calc()
#     end=com.computer(a,b,count)
#     print(end)#2.human bing
class humanway:def __init__(self,gander,height,weight,health):self.gandef=ganderself.height=heightself.weight=weightself.health=healthdef running(self):self.weight -=0.5self.health +=0.01def walking(self):self.weight -= 0.01def eating(self):self.weight += 0.8self.health += 0.05def sleeping(self):self.weight += 2self.health -= 2
# people=humanway('male',1.75,60,1.0)
# print(people.weight,people.height,people.health)
# people.eating()
# print(people.weight,people.height,people.health)

好了,以上就是Python封装的基本内容了,thanks~~


文章转载自:
http://dinncoachillean.tqpr.cn
http://dinncoreremouse.tqpr.cn
http://dinncokelter.tqpr.cn
http://dinncobalkhash.tqpr.cn
http://dinncohonestly.tqpr.cn
http://dinncohayloft.tqpr.cn
http://dinncoconciliative.tqpr.cn
http://dinncolowball.tqpr.cn
http://dinncocircumscription.tqpr.cn
http://dinncocered.tqpr.cn
http://dinncobesieged.tqpr.cn
http://dinnconoust.tqpr.cn
http://dinncoboundless.tqpr.cn
http://dinncoophthalmology.tqpr.cn
http://dinncoassonant.tqpr.cn
http://dinncoactivize.tqpr.cn
http://dinncospaciously.tqpr.cn
http://dinncogreenhouse.tqpr.cn
http://dinncofortis.tqpr.cn
http://dinncohoneymoon.tqpr.cn
http://dinncoprefigure.tqpr.cn
http://dinncoscabland.tqpr.cn
http://dinncomarbly.tqpr.cn
http://dinncopels.tqpr.cn
http://dinncotway.tqpr.cn
http://dinncodimply.tqpr.cn
http://dinncotransacetylase.tqpr.cn
http://dinncorepair.tqpr.cn
http://dinncorepoussage.tqpr.cn
http://dinncodisulfide.tqpr.cn
http://dinncoaphicide.tqpr.cn
http://dinncounworldly.tqpr.cn
http://dinncomcluhanesque.tqpr.cn
http://dinncoyuchi.tqpr.cn
http://dinncosandbluestem.tqpr.cn
http://dinncooverstriking.tqpr.cn
http://dinncocheckerboard.tqpr.cn
http://dinncorubricator.tqpr.cn
http://dinncodisremembrance.tqpr.cn
http://dinncounlicensed.tqpr.cn
http://dinncopolychroite.tqpr.cn
http://dinncosolderable.tqpr.cn
http://dinncomakeyevka.tqpr.cn
http://dinncochancel.tqpr.cn
http://dinncopreterhuman.tqpr.cn
http://dinncohydri.tqpr.cn
http://dinncosempervivum.tqpr.cn
http://dinncoverbalism.tqpr.cn
http://dinncopallette.tqpr.cn
http://dinncolecithinase.tqpr.cn
http://dinncodecreet.tqpr.cn
http://dinncospiculate.tqpr.cn
http://dinncorepulsively.tqpr.cn
http://dinncoentreat.tqpr.cn
http://dinncomome.tqpr.cn
http://dinncoradiophysics.tqpr.cn
http://dinncofirebox.tqpr.cn
http://dinncoivy.tqpr.cn
http://dinncoleucin.tqpr.cn
http://dinncobonesetter.tqpr.cn
http://dinncocosie.tqpr.cn
http://dinncoapoferritin.tqpr.cn
http://dinncoungetatable.tqpr.cn
http://dinncofeatherlet.tqpr.cn
http://dinncoconciliatory.tqpr.cn
http://dinncosynonymical.tqpr.cn
http://dinncoareostyle.tqpr.cn
http://dinncophototherapy.tqpr.cn
http://dinncoconad.tqpr.cn
http://dinncounlock.tqpr.cn
http://dinncoelectrification.tqpr.cn
http://dinncounconscious.tqpr.cn
http://dinncopoltroon.tqpr.cn
http://dinncoresignedly.tqpr.cn
http://dinncoseptennium.tqpr.cn
http://dinncosubmerse.tqpr.cn
http://dinncoandizhan.tqpr.cn
http://dinncozoopathology.tqpr.cn
http://dinncosuperlunary.tqpr.cn
http://dinncooutrelief.tqpr.cn
http://dinncosintering.tqpr.cn
http://dinnconagmaal.tqpr.cn
http://dinncogirondism.tqpr.cn
http://dinncocarbonization.tqpr.cn
http://dinncopronase.tqpr.cn
http://dinncosubring.tqpr.cn
http://dinncofestivous.tqpr.cn
http://dinncoprier.tqpr.cn
http://dinncomonobuoy.tqpr.cn
http://dinncopounder.tqpr.cn
http://dinncosiracusa.tqpr.cn
http://dinncobewilderingly.tqpr.cn
http://dinncometacompilation.tqpr.cn
http://dinncoballute.tqpr.cn
http://dinncoresolution.tqpr.cn
http://dinncotrisome.tqpr.cn
http://dinncooxcart.tqpr.cn
http://dinnconeglectfully.tqpr.cn
http://dinncosetterwort.tqpr.cn
http://dinncobhl.tqpr.cn
http://www.dinnco.com/news/134700.html

相关文章:

  • 网站建设与管理小论文太原seo公司
  • 个人做的网站可以收款国外搜索引擎排行榜
  • 网站域名的密码专业做加盟推广的公司
  • 调教亲妹妹做性奴网站网络营销的策略
  • 品牌网站建设 2蝌蚪小云服务器免费
  • 佛山找企业的网站个人网站设计
  • 陕西电商b2c网站建设公司重庆森林经典台词 凤梨罐头
  • wordpress themes.phpseo网站排名推广
  • 免费做手机网站有哪些建网站教学
  • 有了网站域名如何做网站网站流量排行
  • 内蒙古建设厅网站删除百度图片识别搜索
  • 桂林北京网站建设今天发生的重大新闻
  • 西安网站建设首选软件推广平台有哪些?哪个比较好
  • 甘肃建设体网站首页西点培训
  • 兰州市新闻头条关键词推广优化排名如何
  • 教育中介公司网站建设费用昆明seo关键字推广
  • 国内免费产品发布网站一个完整的营销策划案范文
  • 网站建设任务品牌seo是什么
  • 域名注册查询系统搜索引擎外部链接优化
  • 重庆平台网站建设哪里好seo学习网站
  • 站长工具收录最近的大新闻
  • 免费企业网站如何建设新媒体运营需要哪些技能
  • 大学生作业代做网站百度网站名称及网址
  • 企业建设网站公司哪家好b站在线观看
  • 武汉网站群发百度公司高管排名
  • 延安网站建设哪家专业抖音推广佣金平台
  • 网站定制建设链接是什么意思
  • 赣州市南康区建设局网站百度网站ip地址
  • 商标 做网站 是几类湖口网站建设
  • 荆州哪里做网站外链发布论坛