Skip to content

Tag: class

class and defining __str__

This is the exercise: Write the special method __str__() for CarRecord. Sample output with input: 2009 ‘ABC321’ Year: 2009, VIN: ABC321 The following code is what I have came up with, but I’m receiving an error: TYPEERROR: __str__ returned non-string I can’t figure out where I went wro…

Python: Function scope inside a class

Let’s consider the code below. On first look, one might expect list_1 and list_2 to both have the same content: [“Tom”, “Tom”], but this is not the case. list_1 evaluates to [“Tom”, “Tom”], whereas list_2 evaluates to [“John”, “John&#8221…

How does the statement for creating classes work in Python?

When I create a class Test defining one method “a”, a object Test, whose type is type ,is created. The dir function give-us the names of the attributes/methods of an object. But when I code: I get: from where did this “a” come from? I thought “a” would be a method from a ob…