Answer:
When two objects made of different materials come in contact with each other, like your hair and a hat, for example, electrons can transfer between them. The more prolonged contact, the more electrons move, creating an imbalance of charges between your hair and the hat