Dialogue is different from regular writing, as in you don't really have to stick to grammar rules because everything is dependent on how the character is saying it, as Fili said.
Differentiating between them is simply a matter of imagining how the character is speaking and using the appropriate punctuation to match.
For example, let's say we have batman and he's saying "I am batman."
"I am batman!" He announces as he bursts through the windows of the warehouse, frightening the scheming villains below.
"I am batman." He says in a low voice as he sneaks up behind a villain and wraps his arm around his neck.
"I am batman?" He asks the young boy next to him, not quite sure, because he can't remember anything before waking up.
See, in these various instances, Batman is saying the same thing, but he's saying it differently. The second article on this website may provide some assistance.