I used feedback from the code review SE for an assignment. Do I have to mark it?
Yes, you should ask the professor in advance and make sure he/she understands what CodeReview actually is.
More generally, you should know (and the professor should effectively communicate) what the parameters are for seeking help. I have doubts that very many professors would permit it, but some would.
The reason for assignments isn't because the professor needs the result. It is to cause a change in your brain that won't happen if you take very many short cuts.
Seeking help from the professor or an assistant is different, since they know the actual purpose of the individual assignment (in your learning) and can give hints that won't impede your learning, but help you deepen it. The contributors to CodeReview don't have the context (or usually the background) to do that properly. So you may be sabotoging your learning in pursuit of a better grade. Long term that's a losing game.
Making it functional first was a good step, but there is a lot to good programming beyond functional.
And if you haven't done so, then yes, mark it and point to the source of help. If there weren't already rules around the behavior there should be no reason to punish you and you might get better advice about seeking help from the prof. In fact, you should make the note pretty visible so it just doesn't get lost. Program comments may not be read without some statement at the top pointing to them.
Other than taking a few seconds out of your life, the only reason to not mention it is if you think that your instructor would take points off for it. If you're withholding information that you think would affect your grade, that's dishonest. If you disclose it, the worst your instructor can do is mark off points. If you don't, and your instructor finds out about it, they could theoretically accuse you of plagiarism. Citing sources isn't, as many people seem to think, a protection against copyright claims, but it does immunize you against plagiarism claims. If your instructor hasn't given you instructions on citations, you don't need do to anything more than mention that you had your code reviewed on an online forum and that your instructor can ask you for more details if they wish.
Something labeled a take-home "exam" or "test" would be different from something merely labeled an "assignment"; an exam is designed to inform the instructor of your knowledge level, and there is much more of an implied honor system. If there is confusion as to what that honor system consists of, that should be clarified before working on the test. An assignment is an opportunity to practice and to expose to yourself any areas of not understanding before you're actually tested on it. Since the main beneficiary of it is intended to be you, not the instructor, there is less urgency in clarifying the rules prior to working on it.