Depends on the kid, and depends on when. When you were one, you might have listened to "no", but there are plenty of kids who don't. And it matters because of things like wanting to play in the street. I can't tell a one-year-old what two tons of car moving at 30 miles an hour is going to do to them. But I can train them that every time they play in the street, it hurts.
That sounds cruel. On the other hand, letting them get hit by a car is much more cruel, and not all of us have fenced front yards.
I have no problem with spanking for safety issues. But be careful, because a kid in danger triggers fear and panic in parents, and once the crisis is over, that seems to almost automatically morph into anger. Do not spank in anger, ever.