I am new to Python. In this question I am trying to create a method in python so I can print out the student's information from my input:
class student():
def __init__(self,s=None):
if (s != None):
self.name = s[0]
self.age = s[1]
else:
self.name = ''
self.age = -1
def print_info(self):
print('Name: ',self.name)
print('Age: ',self.age)
The input is:
t = student()
t.add_name('Sam')
t.add_age(21)
print(t)
I expect to get:
Name: Sam Age: 21
I tried many times in this code that gives the error message that "str is not callable" Thanks!