[英]I wrote this code a code with python 3 tkinter and it's giving me an error
[英]Correct me please . The code I wrote was in the notebook
class Student:
workshop = 'python'
def _init_(self, name, age):
self.name = name
self.age = age
def describe(self):
print(self.name,"is",self.age,"years old and participating in",
Student.workshop,"class")
return
student1 = Student("Sridhar", 35 )
student1.name
init
方法需要两个下划线__
。 因此,
改变这个:
def _init_(self, name, age):
对此:
def __init__(self, name, age):
所以:
class Student:
workshop = 'python'
def __init__(self, name, age):
self.name = name
self.age = age
def describe(self):
print(self.name,"is",self.age,"years old and participating in",
Student.workshop,"class")
return
student1 = Student("Sridhar", 35)
print(student1.name)
student1.describe()
OUTPUT:
Sridhar
Sridhar is 35 years old and participating in python class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.