Python: 类 对象 属性Python: 类 对象 属性Python: 类 对象 属性Python: 类 对象 属性
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

Python: 类 对象 属性

发表 admin at 2022年3月3日
类别
  • Practice
标签
class A(object):
    def __init__(self):
        self.var1 = 1


class B(object):
    def __init__(self, arg1):
        self.var2 = arg1
        self.var3 = A()


x = B(2)
y = x.var3.var1
print(type(x)) #x是B类对象
print(type(x.var3)) #x.var3是A类对象
print(type(x.var3.var1)) #x.var3.var1是A类对象属性

发表回复 取消回复

要发表评论,您必须先登录。

类别

  • Cat
  • Python
  • Django
  • Database
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • Maths/AI
  • PHP/Wordpress
  • Practice
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • SEO
  • English
  • Games
  • Recipes
  • General
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader