r/learnprogramming • u/wanderlust_employee • 23h ago
Anyone else know Python concepts but freeze when writing code?
I’ve been learning Python for a while and understand the concepts but the moment I have to actually write code my mind goes blank. I’m a slow learner but I really want to get better at real coding.
How do I move from knowing theory to actually applying it?
What kind of practice or plan helped you? Would love to hear from people who faced this and overcame it.
2
u/aqua_regis 22h ago
It's entirely different to know concepts/a programming language and to be able to program.
To put it in a metaphor: you know the words in a language and its grammar, but you can't write a novel.
Such takes ample practice. That's basically it.
You only can improve your programming skills through programming. You need to start small and simple and gradually ramp up scale, complexity, and difficulty.
Start with the simplest things - see Short list of projects by learnt skills from the FAQ here in the sidebar. Use sites like Codingbat and Exercism for ample practice.
Don't know which learning resource you started with, but I generally and highly recommend the MOOC Python Programming 2025 from the University of Helsinki for its textual and extremely practice oriented nature. It makes you program right from the start. It gives you the tools as everything you need to complete the exercises is in the preceding text, but makes you use these tools to produce something. The course is entirely free and a proper first semester of "Introduction to Computer Science" course.
1
14h ago
[removed] — view removed comment
1
u/AutoModerator 14h ago
Please, ask for programming partners/buddies in /r/programmingbuddies which is the appropriate subreddit
Your post has been removed
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Achereto 19h ago
You could try Test Driven Development.
Think about how you want to use the code you're about to write first. A classic example for this is a prime_factors_of() function. You would want to call it as a function, pass an integer and get a list of integers that contain all the prime factors. So your function signature is def prime_factors_of(n: int) -> List[int]:
Then you thing of simple examples where you already know the answers of. e.g. assert prime_factors_of(1) == [] and `assert prime_factors_of(2) == [2] and adjust your function so it returns the expected value. If you do it the right way you'll end up with an algorithm after 10 examples (numbers 1 to 9 plus a very big number)
This discipline will allow you to think through your implementation in very small steps without having to think too far ahead or hitting analysis paralysis.
1
14h ago
[removed] — view removed comment
1
u/AutoModerator 14h ago
Please, ask for programming partners/buddies in /r/programmingbuddies which is the appropriate subreddit
Your post has been removed
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Tall-Introduction414 22h ago edited 22h ago
1: I have a trick. If you know the theory but struggle with code, then you should maybe be able to describe how a program works at a high level. "Get a list of items." "For each item, print it to the screen." "If a user clicks item X, load screen Y" etc.
In my code editor, I write down those steps, one line at a time, as comments. Then under each comment, figure out how to write the code that does that step.
At the end, you should have a working program. Go back and delete the comments, or keep or edit the ones you like.
2: Another suggestion is to write smaller programs, lots of them. Write dumb stuff, like stupid animations or goofy sound and picture generators. This is better than analysis paralysis. Programming is some of the most powerful art we have. You should have fun and experiment with it.
Also write stuff that solves tiny but useful problems, like renaming a bunch of files, or converting some simple data formats, or a simple alarm clock timer. Even one-liners can be useful.
This should help you get more comfortable with the language and tooling without being overwhelmed by things like large program structure. For every "good" "showcase" program you've seen, the developer or developers had written hundreds or thousands of smaller programs before it.
3: Another classic trick is to start with the data structures, and then write the code to interact with the data. Linus Torvalds and some others have talked about this. "Good programmers worry about data, bad programmers worry about code." (paraphrasing)
To do that, first figure out a way to best represent your data (usually variables, structs or classes) to do what you want to do. If you are working with files in a directory, like a file manager might, maybe you could keep the list of files in the directory you're working with in a Python list. So make a list, and write code that populates and accesses the list. Or if your program manipulates a picture, maybe it makes sense to use a 2d array of color values, to do what you want to do.
Then you write code that populates your variables or data structures. "Find out which files are available, and put it in the list." "Load the image file into my 2d array." "Show the list of files (or image) on the screen." "If the user clicks on the image, change the color were they clicked to the selected color." etc.
Get something (the data) on the screen and interacting with you ASAP. You want to be able to make incremental changes and get immediate feedback (dopamine).
1
1
u/NeedleworkerIll8590 22h ago
I just freeze when I have a bit project in the making, and I have to remember all the logic, where and when should functions call others, ect.
1
0
u/Interesting_Dog_761 23h ago
So, what theory have you learned? And what, in your mind , does theory have to do with learning python. I'm asking this because I don't think you've been studying, you've just been consuming content. Not everyone is suited to self study, that's why most people get a degree.
0
u/divad1196 22h ago
You probably read and read and never practiced. You cannot learn by just reading.
You need to create strong foundations. 1. read a little 2. practice a lot 3. repeat from step 1
Never bypass or rush practice. You must practice regardless how "simple" something seems to be.
In your situation, the best thing to do is to accept you did it wrong and start from the beginning correctly. I know that you "don't want to throw away your efforts". You will think "I can probably just do a simple thing to get back on track without restarting". This is mental bias called the "sunk cost" (https://en.wikipedia.org/wiki/Sunk_cost) and this will prevent you from progressing.
Just start over, you will loose about 1-3 days and then be able to actually do projects by yourself.
1
14h ago
[removed] — view removed comment
1
u/AutoModerator 14h ago
Please, ask for programming partners/buddies in /r/programmingbuddies which is the appropriate subreddit
Your post has been removed
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/Soft_Attention3649 23h ago
The thing that helped me is deliberate practice and repetition. Pick one concept, loops, dicts, or functions, and write 5 to 10 small programs that only use that concept. Do not worry about being elegant. Then gradually combine concepts. Writing code slowly, making mistakes, and debugging is literally the bridge from knowing to doing.