• 技术文章 >Python技术 >Python基础教程

    python __init__()的使用注意

    小妮浅浅小妮浅浅2021-08-31 10:14:32原创1835

    使用注意

    1、init()方法在创建一个对象时默认被调整,不需要调整。

    2、init(self)中的self参数不需要开发者传输,python解释器会动员传输当前对象。

    实例

    class Washer():
        def __init__(self) -> None:
            self.height=1000
            self.width=10
        def wash(self):
            print(f'宽度是:{self.width},高度是{self.height}')
     
     
    haier1=Washer()
    print(haier1.height)
    print(haier1.width)
    haier1.wash()

    以上就是python __init__()的使用注意,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python __init__
    品易云
    上一篇:python email模块的使用 下一篇:python随机数种子的特性

    相关文章推荐

    • python plotly如何创建滑块和选择器• python unittest单元测试的过程• python元组如何打包和解包• python归并排序如何理解• python非绑定方法是什么• Python解释器有哪些种类• python字典如何进行运算• python numpy.dot的点乘运算• python numpy.matmul实现矩阵相乘• python smtplib模块的使用• python smtplib和邮件系统交互• python email模块的使用

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网