Instantiating a class - Python -


i'm trying instantiate straightforward class in python.

class student:     def __init__(self, name, age, major, gpa):         name = self.name         age = self.age         major = self.major         gpa = self.gpa   def main():     student_1 = student('john', 31, 'history', 3.4)     student_2 = student('george', 31, 'english', 3.5)     print student_1.name, student_2.name 

the error is:

attributeerror: student instance has no attribute 'name'

change:

    name = self.name     age = self.age     major = self.major     gpa = self.gpa 

to:

    self.name = name     self.age = age     self.major = major     self.gpa = gpa 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -