__init__() takes exactly 2 arguments (1 given)?

后端 未结 3 1592
刺人心
刺人心 2020-12-12 08:01

I would like to know where am lagging, Looking for your advices..

class Student_Record(object):

    def __init__(self,s):
        self.s=\"class_Library\"
          


        
3条回答
  •  余生分开走
    2020-12-12 08:50

    if you do

    class Student_Record(object):
    
        def __init__(self, s):
            self.s = ""
    
        def Student_details(self):
            print " Please enter your details below"
    

    when you create the object of class Student_Record it should accept a parameter despite for itself (self). so it looks like:

    record = Student_Record("text")
    

    and in __init__ you can do whatever with the passed-in variable s. For example, self.s = s and you can call it anywhere in the class with self.s because it has been initialized.

提交回复
热议问题