I learned by playing with Apple Basic when I was a kid, reading the user manual that came with the Apple ][. I was drawn to it because it was fun... but I then put it away for my teenage years because other things were more fun. I actually got productive with code when I started work after college. I had an IT job, and learned from the top-down, writing scripts to help the work, writing low-code apps, and going deeper and more complex with each new project. It was a couple years later when my job officially changed to being a full-time developer.
I've now been doing it for a couple more decades... and I'm still learning. Learning to code is not something to learn and then do. It is something you learn continually for your entire career.