11. Warning: Here Be Dragons


#1



I go through the class exercises but still find it hard to understand what actually self.xxx= xxx line say. Can someone explain me how the code interprets this line of code?

Thanks


class Customer(object):
    """Produces objects that represent customers."""
    def __init__(self, customer_id):
        self.customer_id = customer_id


#2

the best way to demonstrate this is by creating a class instance:

class Customer(object):
    """Produces objects that represent customers."""
    def __init__(self, customer_id):
        self.customer_id = customer_id

# class instances
customer1 = Customer(10)
customer2 = Customer(20)
custome3 = Customer(30)

so customer_id is a instance variable, its different for every class instance. by doing self.customer_id = customer_id, you make the member variable accessible through self.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.