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

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -