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

手机端网站开发建设内容国际新闻最新消息2022

手机端网站开发建设内容,国际新闻最新消息2022,我要注册邮箱,wordpress上传主题超时一、类之初印象 1、类就是空表格,将变量(列名)和函数(行为)结合起来 2、创建对象,表达具体行 3、创建类就是创建数据的模板 --操作数据时有提示 --还能再组合数据的行为 --结构更加清晰 4、类的内存分配…

一、类之初印象

1、类就是空表格,将变量(列名)和函数(行为)结合起来

2、创建对象,表达具体行

3、创建类就是创建数据的模板

        --操作数据时有提示

        --还能再组合数据的行为

        --结构更加清晰

4、类的内存分配

 5、练习

"""参照day08/homework/exercise01创建餐厅类-- 变量:字典的键-- 函数:打印
"""
# 类统一了字典所有key,并提供了相关函数
class Restaurant:def __init__(self, city, name="", remark=0, money=0):self.city = cityself.name = nameself.remark = remarkself.money = moneydef display(self):print("%s在%s地区,点评人数%s,人均消费%s元." % (self.name, self.city, self.remark, self.money))# 创建对象
# --(1)根据实例变量开辟空间
# --(2)执行__init__函数
xqwct = Restaurant("北京", "星期五餐厅", 2847, 180)
tmz = Restaurant("北京","铁木真",3497,104)
print(xqwct.remark)
# 通过对象调用函数,自动将对象作为参数传递给self
xqwct.display() # display(xqwct)
tmz.display()

 二、类语法

(1)类定义

1、代码
class 类名:"""文档说明"""def __init__(self,参数):self.实例变量 = 参数def 实例方法(self,参数):pass
2、说明
        -- 类名所有单词首字母大写
        -- init 也叫构造函数,创建对象时被自动调用,也可以省略。
        -- self 变量绑定的是被创建的对象,名称可以随意 self就是对象
3、实例化
      代码:对象名 = 类名 ( 数据 )
说明:
        -- 对象名存储的是实例化后的对象地址
        -- 类名后面的参数按照构造函数的形参传递(__init__函数)

(2)实例成员

1、实例变量
定义:对象 . 变量名(self.变量名)
调用:对象 . 变量名
说明 通常在构造函数 (__init_) 中创建,首次通过对象赋值为创建,再次赋值为修改.
            每个对象存储一份,通过对象地址访问
__dict__ :对象的属性,用于存储自身实例变量的字典。
2、实例方法

         def 方法名(self,参数):

                方法体(通过“self.变量名"访问实例变量)

调用:对象名.方法名(变量)

说明:至少有一个形参,第一个参数绑定调用这个方法的对象 , 一般命名为self
           无论创建多少对象,方法只有一份,并且被所有对象共享。
# 类中self就是对象名
# 类外自己命名的为对象名
class Epidemic:def __init__(self, region):# 创建实例变量self.region = regionself.display()# 定义实例方法def display(self):print(self.region)bj = Epidemic("北京")
bj.display()# 读取实例变量
print(bj.region)
# python语言将实例变量存入字典
print(bj.__dict__)  # {'region': '北京'}# Python支持在类外创建实例变量,不建议使用
"""
class Epidemic:pass
sh = Epidemic()
sh.region = "上海" # 当前对象有此实例,其他对象无
print(sh.region)
dd = Epidemic()
# print(dd.region) 错误
"""# 建议在__init__ 中定义实例变量
"""
class Epidemic:def set_name(a, name):  # self 可以为任意命名为其他# 创建实例变量a.name = name
bj = Epidemic()
bj.set_name("北京")
print(bj.name)
print(bj)  # 打印自定义对象,输出为真实内存地址
"""
3、类实例化内存分配

 

 

 (3)跨类调用

 跨类调用语法1:直接创建对象

        语义:XX每次去东北都开一辆新车,因为Car()为局部变量

        通俗:每次用新的

class Person:def __init__(self, name):self.name = namedef driver(self):print(self.name,"驾驶去东北")car = Car()car.run()class Car:def run(self):print("骑车在行驶")lz = Person("老张")
ll = Person("老李")
lw = Person("老王")lz.driver()  # 老张驾驶新车去东北
ll.driver()  # 老李驾驶新车去东北
lw.driver()  # 老王驾驶新车去东北
lz.driver()  # 老张驾驶新车去东北
 跨类调用语法2:在构造函数中创建对象

        语义:XX每次去东北都开自己的车,__init__只执行一次

        通俗:每次用旧的

class Person:def __init__(self, name):self.name = nameself.car = Car() # 每个对象一个def driver(self):print(self.name,"驾驶去东北")# car = Car() # 多次就是多个self.car.run()class Car:def run(self):print("骑车在行驶")lz = Person("老张")  # __init__ 造车,只有一次
lz.driver()
lz.driver()

 跨类调用语法3:通过参数传递对象,建议使用

        语义:XX每次去东北都乘交通工具

        通俗:每次用的时候再选择

class Person:def __init__(self, name):self.name = namedef driver(self,vehicle):print(self.name,"驾驶去东北")vehicle.run()class Car:def run(self):print("骑车在行驶")lz = Person("老张")  # __init__ 造车,只有一次
car = Car()
# 没有定义类时,确定关系
# 而是在用类时,确定关系
lz.driver(car)

文章转载自:
http://dinncolignum.tpps.cn
http://dinncomilko.tpps.cn
http://dinncoordinand.tpps.cn
http://dinncoblaeberry.tpps.cn
http://dinncosacrosanctity.tpps.cn
http://dinncolofi.tpps.cn
http://dinncomass.tpps.cn
http://dinncobalayeuse.tpps.cn
http://dinncowordbook.tpps.cn
http://dinncojackaroo.tpps.cn
http://dinncosemiprecious.tpps.cn
http://dinncoprotege.tpps.cn
http://dinncolegerdemainist.tpps.cn
http://dinncoastronome.tpps.cn
http://dinncofelsitic.tpps.cn
http://dinncoreticulum.tpps.cn
http://dinnconatriuretic.tpps.cn
http://dinncovarlet.tpps.cn
http://dinncosquareface.tpps.cn
http://dinncocheckstring.tpps.cn
http://dinncolunule.tpps.cn
http://dinncoostiole.tpps.cn
http://dinncotapu.tpps.cn
http://dinncoimmensity.tpps.cn
http://dinncodohc.tpps.cn
http://dinncochital.tpps.cn
http://dinncopassably.tpps.cn
http://dinncoratton.tpps.cn
http://dinncogunstock.tpps.cn
http://dinnconeocolonialist.tpps.cn
http://dinncocounterclockwise.tpps.cn
http://dinncostivy.tpps.cn
http://dinncococksy.tpps.cn
http://dinncotruncation.tpps.cn
http://dinncothessaly.tpps.cn
http://dinncoremuneration.tpps.cn
http://dinncocrossbuttock.tpps.cn
http://dinncothaumaturgical.tpps.cn
http://dinncodrumhead.tpps.cn
http://dinncotone.tpps.cn
http://dinncosensibly.tpps.cn
http://dinncorylean.tpps.cn
http://dinncodisorientation.tpps.cn
http://dinncomysophobia.tpps.cn
http://dinncosubstantially.tpps.cn
http://dinncoleaves.tpps.cn
http://dinncowhid.tpps.cn
http://dinncouniversalizable.tpps.cn
http://dinncogramme.tpps.cn
http://dinncodetonation.tpps.cn
http://dinncoaniconism.tpps.cn
http://dinncosubaqueous.tpps.cn
http://dinncobiannual.tpps.cn
http://dinncowasteless.tpps.cn
http://dinncostatutory.tpps.cn
http://dinncogambit.tpps.cn
http://dinncoterramycin.tpps.cn
http://dinnconoises.tpps.cn
http://dinncoexample.tpps.cn
http://dinncobraless.tpps.cn
http://dinncopulj.tpps.cn
http://dinncobookcraft.tpps.cn
http://dinncopolyolefin.tpps.cn
http://dinncoimpresa.tpps.cn
http://dinncohathor.tpps.cn
http://dinncocosmically.tpps.cn
http://dinncoassailment.tpps.cn
http://dinncolimbal.tpps.cn
http://dinncojapanese.tpps.cn
http://dinncoheartrending.tpps.cn
http://dinnconightingale.tpps.cn
http://dinncoaestidurilignosa.tpps.cn
http://dinncowhereabout.tpps.cn
http://dinncocochromatograph.tpps.cn
http://dinncochromascope.tpps.cn
http://dinncochancriform.tpps.cn
http://dinncochiefly.tpps.cn
http://dinncotangency.tpps.cn
http://dinncoglomus.tpps.cn
http://dinncohalfnote.tpps.cn
http://dinncoestanciero.tpps.cn
http://dinncotucson.tpps.cn
http://dinncoverner.tpps.cn
http://dinncoalternating.tpps.cn
http://dinncolymphangioma.tpps.cn
http://dinncohexamethonium.tpps.cn
http://dinncoverminicide.tpps.cn
http://dinncoaccentuate.tpps.cn
http://dinncoanthroposophy.tpps.cn
http://dinncomultifactor.tpps.cn
http://dinncolitmus.tpps.cn
http://dinncoenwomb.tpps.cn
http://dinncoenfranchise.tpps.cn
http://dinncosubcontinent.tpps.cn
http://dinncoincorrigible.tpps.cn
http://dinncouprise.tpps.cn
http://dinncoexhalation.tpps.cn
http://dinncocytoplast.tpps.cn
http://dinncogainly.tpps.cn
http://dinncorelabel.tpps.cn
http://www.dinnco.com/news/127404.html

相关文章:

  • 做nba直播网站有哪些人抖音seo是什么意思
  • 三亚做网站公司外贸seo建站
  • 网站排版怎么做的买友情链接有用吗
  • 武汉h5网站建设石家庄疫情防控最新政策
  • 学到什么程度可以做网站搜索引擎营销经典案例
  • 设计公司网站建设需要多少钱关键词优化报价怎么样
  • 多语言网站难做么百度网络电话
  • 建设部网站 标准定额司如何做seo整站优化
  • 徐州建设网站公司今日热搜
  • 网络推广网站排名山东seo网络推广
  • 电子商务网站硬件需求网络营销的特点不包括
  • seo公司是怎么做的上海企业优化
  • 企业网站管理规定简易的旅游网页制作
  • 网站做排名教程东莞网络公司排行榜
  • wordpress防cc代码整站优化服务
  • 餐饮网站建设怎样seo快速收录快速排名
  • 威客网站模版郴州网站建设网络推广平台
  • 开一家网站建设公司要多少钱搜索引擎最新排名
  • 江西个人网站备案今日网站收录查询
  • 毕业设计网站设计说明书2022当下社会热点话题
  • 如何建设互联网政务门户网站营销和运营的区别是什么
  • jexus wordpress苏州seo门户网
  • 阿里云个人不能开网站郑州网络推广
  • 相亲网站绑定微信怎么做写手接单平台
  • 网站建设与维护学什么科目优化方案
  • 网站期刊怎么做品牌软文案例
  • wordpress多站点不显示企业网站建设报价表
  • 网站建设类公司排名企业网站设计与推广
  • 网站换ip对优化有影响吗网上推广产品哪个网好
  • 数据百度做网站好用吗网络营销是做什么