默认构造函数不显示输出

问题描述 投票:0回答:1

运行时不会产生任何输出

class Levels:
     def __int__(self):
          print("Welcome to Constructors")

 a = Levels()
 b = Levels()
python constructor pycharm default-constructor
1个回答
0
投票

构造函数声明的正确语法:

def __init__(self):
    # body of the constructor

示例:

class Levels:
  def __init__(self):
    print('Welcome to Constructors')

a = Levels()
© www.soinside.com 2019 - 2024. All rights reserved.