Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
For each name in the lines below, say whether it is a class, an object, an attribute or a method.
numbers = [3, 1, 2]
numbers.sort()
z = 3 + 4j
z.imag
type(numbers)
strName: numbers, sort, z, imag, list (the answer of type(numbers)), str.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. An object is one example. A class is a kind. An attribute is data of an object, and a method is an action.
numbers: an object, one list.sort: a method of the list object. It is called with brackets.z: an object, one complex number.imag: an attribute of z, its imaginary part. It is read without brackets.list: a class, the kind of numbers.str: a class, the kind of all texts.Check. Ask: can I call it with brackets as an action (method)? Is it a kind that I can make examples of (class)? Is it data inside an object (attribute)?
Answer: object, method, object, attribute, class, class.
Log in to join the discussion.
Loading…