Am I understanding 'self'?


#1



Why Use Classes


Would it be correct to say "self" is just an alternative for the class name. e.g. self.name is the same as Fruit.name.


class Fruit(object):
    """A class that makes various tasty fruits."""
    def __init__(self, name, color, flavor, poisonous):
        self.name = name
        self.color = color
        self.flavor = flavor
        self.poisonous = poisonous


#2

You're close.

It isn't the Class name, but the object name.

So it would be Pear instead of Fruit.


#3

Thank you cadecodes :grin:


#4

You're welcome!

Post again if you get confused. :slight_smile: