I'm trying to learn using classes in Python, and have written this test program. It is to some extent based on code I found in another question I found here on Stack OverFlow.
The code looks as follows:
class Student(object):
name = ""
age = 0
major = ""
# The class "constructor" - It's actually an initializer
def __init__(self, name, age, major):
self.name = name
self.age = age
self.major = major
def list_values():
print "Name: ", self.name
print "Age: ", self.age
print "Major: ", self.major
def make_student(name, age, major):
student = Student(name, age, major)
return student
print "A list of students."
Steve = make_student("Steven Schultz",23,"English")
Johnny = make_student("Jonathan Rosenberg",24,"Biology")
Penny = make_student("Penelope Meramveliotakis",21,"Physics")
Steve.list_values()
Johnny.list_values()
Penny.list_values()
When I run this, get the error "TypeError: list_values() takes no arguments (1 given)". In my oppinion I have not given any arguments, but I remove the parenthesis, giving the code
Steve.list_values
Johnny.list_values
Penny.list_values
This renders no errors, but does not do anything - nothing gets printed.
My questions:
- What's the deal with the parenthesis?
- What's the deal with the print statements?