web crawlers – is preventing Googlebot from accessing certain parts of the site with the robots.txt file penalized by Google?

I read this question.
Let's say I have a div with something useful for users but I do not want that to be taken into account by Google.
If I put this on an iframe and blocks the googlebot with robots.txt so that it does not read it. Will I be penalized?

Google has it already clarified? Or maybe by experience, someone can confirm that it is correct, or not?