When do you use a comma in a sentence

A comma is used in a sentence in various situations, including:

1. To separate items in a list: "I need to buy apples, bananas, and oranges."
2. To separate two or more adjectives that modify the same noun: "She has beautiful, long hair."
3. To separate independent clauses connected by coordinating conjunctions (and, but, or, etc.): "I wanted to go for a walk, but it started raining."
4. To separate introductory elements or phrases from the main part of a sentence: "On the other hand, I believe in second chances."
5. To set off nonessential or parenthetical information: "The girl, wearing a blue dress, smiled at me."
6. To separate direct speech or quotations from the rest of the sentence: He said, "I'll be there in five minutes."
7. To indicate a pause or a change in thought: "I love hiking, swimming, and running - they are my favorite activities."

It's important to note that the use of commas can vary depending on the specific style guide or grammar rules followed.