Blogger Information
Blog 75
fans 0
comment 0
visits 54676
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈python之python调用内部类的两种方法
聆听的博客
Original
545 people have browsed it

python是怎么调用内部类的,有哪些方法呢?小猿圈加加这篇文章详细介绍一下python调用内部类的两种方法,不懂的朋友们可以看过来了。

实例

class Car:#外部类
    class Door:#内部类
        def open(self):
            print('open door')
        
    class Wheel:
        def run(self):
            print('car run')
            
if __name__=="__main__":
    car=Car()#实例化外部类
    backDoor=Car.Door()#实例化内部类 第一种方法

    frontDoor=car.Door()#因为car已经实例化外部类,再次实例化Car的内部类 第二种方法
    backDoor.open()
    frontDoor.open()
    wheel=car.Wheel()#car已经实例化外部类,Wheel()再次实例化内部类
    wheel.run()#调用内部类的方法

运行实例 »

点击 "运行实例" 按钮查看在线实例

学会了吗?这就是python调用内部类的两种方法,python不仅可以调用方法,还可以调用类,很强大吧,学会了的朋友可以自己敲一下代码练习一下,又掌握一个小技巧,其实小编和你们一样,刚刚学会就分享给你们了,如果你们也想知道很多小技巧,可以和小编一样去小猿圈学习技巧。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!