Error is function call - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Error is function call (/thread-5073.html) |
Error is function call - Oracle_Rahul - Sep-17-2017 How to resolve the before error students = {}; def add_student(name, student_id=332) : student = {"name": name, "student_id": student_id} students.append(student); add_student("Rahul", 12);
RE: Error is function call - ichabod801 - Sep-17-2017 As it says, you can't append to a dict, append is for lists, typically. It's not clear what your target data structure is here. If you do want a list of students, change the first line to students = [] . If you want a dictionary of students that you can retrieve by student ID, I would replace the body of add_student with students[id] = name .
RE: Error is function call - nilamo - Sep-21-2017 Quote: You can resolve the error by changing your data type to be something that has an append method, or changing your method to be something that exists in a dict. |