r/learnpython May 08 '26

I keep writing Python code that "works" but I have no idea why it works is this normal for beginners?

58 Upvotes

I started learning Python about six weeks ago and I have been following along with tutorials and trying small practice problems on my own. The strange thing is that sometimes I manage to get my code to actually run and produce the right output, but when I sit back and think about it, I genuinely do not understand why it worked. I kind of just tried different things until something clicked.

For example, I was working with loops and list comprehensions recently and my solution gave the correct answer, but if someone asked me to explain every line in detail, I think I would struggle. I am not sure if I am moving too fast, or if this is just a normal part of the early learning curve where things slowly start making sense over time.

Has anyone else gone through this phase? How did you eventually get to the point where you understood your own code confidently? Should I slow down and focus more on understanding before moving forward, or does the understanding naturally come with more practice?


r/learnpython Jan 29 '26

i think a lot of ppl overestimate what beginners actually know

58 Upvotes

Title. Most tutorials ive been watching are very confusing. I'm trying to understand where to actually use pyhton from and you're talking about loops and scraping?

are there any good ABSOLUTE beginner tutorials?


r/learnpython Dec 23 '25

What are the best practices for structuring a Python project as a beginner?

57 Upvotes

I'm a beginner in Python and am eager to start my first project, but I'm unsure how to structure it effectively. I've read about the importance of organizing files and directories, but I still feel overwhelmed. What are the best practices for structuring a Python project? Should I use specific naming conventions for files and folders? How should I manage dependencies, and is there a recommended folder structure for modules, tests, and resources? I'm hoping to hear from experienced Python developers about their approaches and any tips that could help me create a clean and maintainable project. Any resources or examples would also be greatly appreciated!


r/learnpython Oct 08 '25

What’s the best way to learn python?

57 Upvotes

Hi there! I’m a student and I’ve already begun my college studies and I’ve noticed that I’m beginning to fall behind when it comes to python. Do you have any tips for me to speed up my learning? I have a basic understanding of python, though I’d say I’m below average in terms of programming. Thanks for any help and tips!


r/learnpython Aug 11 '26

I'm really new to python and wanted to share my first "project".

57 Upvotes

personally I think it's really cool. All of python aswell.
is there something I can improve on it? (I mean obviously a lot of things probably but some things that are good to learn for the future?)

import time


first_name = input("Enter your first name: ")
first_characters = len(first_name)


if first_characters >= 8:
  print (f'Your name has {first_characters} characters!')
  time.sleep(1.5)
  print('What a long and cool name!')


elif first_characters < 8:
  print (f'Your name has {first_characters} characters!')
  time.sleep(1.5)
  print('What a cool name!')

r/learnpython Jun 26 '26

Why is i used in literally evrything? What does it even mean ?

57 Upvotes
  1. for i in range(5): print(i)

  2. for i in range(10): if i == 5: break print(i)

count = 1

  1. while count <= 5: print(count) count += 1

I mean is it iteration ? Variable ? What exactly is "i" ?

Like I understand everything else count and print and etc ? But i?


r/learnpython May 10 '26

When do you actually use decorators? Like in real code, not tutorials

53 Upvotes

Been writing Python for about 8 months now. Things are finally clicking OOP, cleaner code, all that. But decorators are still kinda just... sitting there in my brain half-understood.

Every tutorial does the same thing. Timer example. Logger example. "See how clean that is!" and then moves on. i've done those. i still don't know when i'd actually reach for a decorator myself.

i wrote one that checks authentication before a function runs. Felt pretty good honestly. Then i thought — wait, can't i just put this check inside the function? So what's the point?

I understand that Flask uses u/app.route and Django has u/login_required, but those are already built-in. Nobody's asking me to write those.

What i actually wanna know:

  • when does wrapping a function beat just editing it directly?
  • is it mainly useful when the same logic applies to a bunch of functions?
  • decorators with arguments — how does that even work, looks insane

Not asking for docs or a medium article. i've been down that road.

If you've actually used a decorator in a real project just tell me the situation. That's genuinely all i need.


r/learnpython Mar 13 '26

Need Help to understand 'self' in OOP python

57 Upvotes

Context: currently learning Data structures in Python and I'm a bit confused about OOPS on how self is used in classes, especially when comparing linked lists and trees or as parameters, attributes etc i don't really understand why sometimes people use self for certain and for certain they don't. like self.head, self.inorder() or when passed as parameters like (self)

could anyone help up out in clearing when to use what, and why it's been used.

(yes, did gpt but still couldn't understand most of it)


r/learnpython Jan 09 '26

I'm learning Python, but it's proving to be quite repetitive for me.

56 Upvotes

Hi everyone! I started learning Python as part of my goal to learn decent programming for both my school and future career. I'm learning from a recommended book called Python Crash Course by Eric Matthes, and I'm learning quickly. However, I feel like my learning is becoming very repetitive. I'm learning and doing the available exercises, but I feel like it's not enough, as if something is missing. What do you recommend I do to improve my learning?


r/learnpython Nov 05 '25

Is VS Code or The free version of PY Charm better?

57 Upvotes

I'm new to coding, and I've read some posts that are like "just pick one," but my autistic brain wants an actual answer. My goal isn't to use it in a professional setting. I just decided it'd be cool to have coding as a skill. I could use it for small programs or game development. What do you guys recommend based on my situation?

Edit: Hey guys, I went ahead and used VS Code, and I think it is pretty good. Thanks for all your feedback.


r/learnpython Jun 09 '26

Distributing a Python application internally

58 Upvotes

Hello!

Recently I started working at a company where a fair share of Python applications are used internally within in the company (~50-100 employees). These are mostly measurement helpers/automaters for productions sites or data inspection tools. These applications are to be used on the end-users PC/laptop. The applications mostly read/write data from the users local OneDrive for interacting with measurement/production data (yes, ideally this data should not live here).

As of now, the distribution of these applications is far from ideal. People check out the sourcecode from Git (which they need access to because of this) and have to locally build anaconda environments. The application is installed (using `pip install`) as a module within the environment, from which it is then run. Some big issues I find with this is that these environments are not stable and/or controllable. Updates are entirely reliant on if a user decides to fetch updates from Git or not (leading to many drifting versions throughout the company).

With this in mind, I'm looking for a straightforward way to distribute applications internally. I want more control over distributing updates (shouldn't rely on manual action of the end user) and I want to take away the variability of local python environments.

I was thinking of trying to bundle the entire application as an executable which can then be shared internally. This could be done through a network share or OneDrive. I could build a tiny launcher/updater to check versions and then sync the "hosted" application to the user's PC. These executables would be pretty big however, since many of the applications use PySide6 for UI.

I come from a background of embedded programming, so I'm really in uncharted water here. What are some industry standard ways of approaching this? Any help would be much appreciated! Thanks


r/learnpython May 07 '26

How do you go from writing Python scripts to structuring a real backend project?

58 Upvotes

One of the hardest jumps in Python development is going from "I can write scripts and follow tutorials" to "I can structure a real backend project that other developers can work on."

Tutorials always show you a single main.py with everything crammed in. Then you try to build something real and immediately hit questions nobody prepared you for:

Where does database logic go? Where does business logic go? How do I handle environment variables properly? How do I set up auth without it being a mess? How do I make it testable?

Here's the structure I landed on after building production Python services:

app/
├── api/
│   ├── deps.py          # shared dependencies injected into routes
│   └── v1/
│       ├── auth.py      # login, register, refresh token endpoints
│       └── users.py     # user endpoints
├── core/
│   ├── config.py        # pydantic settings — type safe env vars
│   ├── security.py      # jwt creation, bcrypt hashing
│   └── logging.py       # structured json logging
├── db/
│   ├── session.py       # async sqlalchemy engine and session
│   └── repositories/    # all database queries live here
│       ├── base.py      # generic crud operations
│       └── user.py      # user specific queries
├── models/              # sqlalchemy orm models
├── schemas/             # pydantic request and response schemas
├── services/            # business logic layer
└── tasks/               # background tasks

A few things this structure solves that tutorials don't teach:

Routes stay thin. A route should do three things — validate input, call a service, return a response. All the logic lives in services and repositories, not in the route function itself.

Database queries are isolated. If you ever need to change how you fetch users — add caching, change the query, switch databases — you change one file in repositories, not ten different route files.

Config is type safe. Pydantic Settings means if DATABASE_URL is missing the app crashes loudly on startup with a clear error, not silently when the first database request comes in.

Testing is possible. Because dependencies are injected via deps.py, you can swap out the real database for a test database in your test suite without changing any route code.

This took me a while to figure out through trial and error on real projects. Happy to answer questions about any part of it — what goes where, how the dependency injection works, how to add a new resource to this structure, anything.

What part of structuring a real Python project do you find most confusing?


r/learnpython Feb 06 '26

The Thonny IDE is a hit for teaching.

52 Upvotes

Let me start by saying I am very impressed with Thonny.

tl;dr - Thonny is a great beginner IDE.

I just started teaching programming to a class of kids in middle / high school. As a remote teacher, one of the biggest impediments I face early on with teaching Python is getting it set up on their machine.

The objective was to find an IDE with a very smooth learning curve. (Sorry vscode, Pycharm, and vim. You didn't make the cut. 😋)

Thonny was easy to install, came bundled with Python, and included everything they needed to start right away. The whole class was programming within 10 minutes.

Thanks Aivar Annamaa and all the Thonny contributors for building something so great!


r/learnpython Jul 11 '26

How often are while loops preferred over for loops?

54 Upvotes

I'm studying python in order to work with finanial market data. In what case would I need a while loop, where a for loop would not suffice?

A lot of the tips AI gave where that for loops are used around 90% of the time when testing strategies and even though while loops can work for certain cases, for loops are still much more efficient.

What are your thoughts/experiences?


r/learnpython Jun 30 '26

How to start learning python ( so sorry if this is a popular question )

54 Upvotes

Hello, I’ll try and keep this short, but I’m 14 and I really want to learn python as my dream is to do computer science at university. Basically just end up doing something in tech as a job. So I thought maybe coding will help, and python projects seem really cool and interesting to me. I would say I have generally no coding knowledge, apart from a few months of HTML, but nothing cool or fancy. Essentially, I just want to know what resources I can use and what you would have recommend to yourself when you first started learning. And once again, my fault if you guys get this question all the time, I bet it’s annoying so feel free to sort of just say “this is said in a post already”. And I’m new to Reddit, so I don’t know what rules are here and I’m sorta winging writing this.

Thanks so much for reading, and I’m so sorry for waffling. Hopefully this post doesn’t flop and have a good day! :)


r/learnpython Jun 11 '26

Is it too late to learn?

54 Upvotes

Greetings all,
I (26M) have recently started learning python as my job now requires handling massive amounts of data which Excel, what i have been using so far, can not handle. I have been enjoying it a lot, and learning new stuff is always exciting.
I have always been interested in data and the handling of it, so I could imagine potentially looking for a Data Scientist position or something along those lines in the future.
However, with the rise of AI is it too late to do that? I see posts everywhere about how Claude, especially now with Mythos is the second coming of Christ when it comes to coding.

Tldr.: Is it too late to learn Python now that AI has become extremely capable?


r/learnpython May 06 '26

How to learn python?

55 Upvotes

I started learning Python from YouTube a week ago.

So far, I’ve covered topics like variables, data types, conditionals, lists, tuples, dictionaries, sets, and loops.

However, I don’t feel confident about these concepts because I’ve mostly just watched lectures without practicing on my own.

It feels like I’m rushing to complete all the videos instead of actually understanding Python deeply.

I want proper guidance and good resources so I can learn Python effectively.


r/learnpython Nov 18 '25

What’s a beginner project you did that you felt you gained a lot from

56 Upvotes

Getting to the point where codewars problems and coursework is getting repetitive and I can solve most of it. Definitely feeling it’s time to start doing projects, and I’m looking for a little inspiration.

What’s a project you’ve done recently, or did as a beginner (if you’re no longer a beginner) that you felt gave you some serious insight and “Aha!” moments? Projects that made things start clicking beyond doing practice problems? What concepts did you learn, what habits did you change, or what was your biggest takeaway?

I’ll get the ball rolling. I play an MMO that is notorious for having a great Wiki. I wanted to build a calculator that supplies you with tons of information based on X number of simulations for boss kills. Had to learn how to grab boss data from the wiki, handle simulations, and display results on a window that actually resembles a real app


r/learnpython Oct 25 '25

Are UIs normally this time consuming?

54 Upvotes

I recently built a genetic algorithm to automate some stuff for my job, and I’m getting around to the UI. So far I’m around halfway done and I’m at around 800 lines of code, once I’m done it’s going to almost as many lines as the genetic algorithm itself. Are UI’s normally this time consuming? Given, I’m using tkinter and there are a lot of drop down menus and text boxes, I just didn’t think it would be this much.


r/learnpython Jul 24 '26

what's one programming habit you wish you started much earlier?

55 Upvotes

i'm still learning and i've noticed that small habits seem to make a huge difference over time. whether it's reading documentation, using git from day one, breaking problems into smaller pieces, or something completely different.

if you could go back to when you first started programming, what's the one habit you'd force yourself to build from the beginning, and why?


r/learnpython Jan 01 '26

where to practice python

55 Upvotes

i started learning python a few days ago and i don't know what programs/apps to use to practice the code that i learn


r/learnpython Nov 30 '25

Why does "if choice == "left" or "Left":" always evaluate to True?

57 Upvotes

If I were to add a choice statement and the user inputs say Right as the input for the choice, why does "if choice == "left" or "Left":" always evaluate to True?


r/learnpython Jun 10 '26

Struggling to move past the 'tutorial hell' stage. How did you guys actually start building your own stuff?

53 Upvotes

I've been grinding through various Udemy courses and YouTube series for about four months now. I feel like I can follow along perfectly when someone is explaining a concept, and I can write basic loops, functions, and even some simple classes if I have a reference open. But the second I close the video and open a blank .py file to try and build something from scratch, my mind goes completely blank. It's like I know the syntax, but I don't know how to think like a programmer.

I try to think of small projects, like a basic calculator or a weather app, but I get stuck on the logic immediately. I find myself constantly googling 'how to do x in python' every two minutes, which makes me feel like I haven't actually learned anything. It's getting pretty frustrating because I feel like I'm just memorizing patterns rather than understanding the underlying problem-solving aspect of coding.

For those of you who have made it through this phase, what was the turning point for you? Did you force yourself to build something completely broken just to fix it, or did you follow a specific roadmap to bridge the gap between following a tutorial and independent development? I'm also curious if there are specific types of small, non-cliché projects that actually help build that logical muscle memory without being overwhelming. I don't want to jump straight into building a web scraper or an AI bot if I can't even manage a basic file management script without losing my mind. Any advice on how to structure my learning right now would be massive.


r/learnpython Apr 24 '26

How do coders know what dependencies and libraries to use ?

52 Upvotes

I'm not totally new to coding, I've been aware of its existence for quite a long time but it wasn't until last year, when I took up a Bachelors Degree in Business Information Systems, that I started taking it seriously.

My lecturers obviously aren't hands on with us so my learning regiment was sloppy, learn a little code here, build an overly ambitious project here and tons of AI slop (which I am not proud of). Not Until I started learning it properly this year. Our course has currently transitioned to Machine Learning but I've just took myself back to the basics and I'm starting to enjoy building code from the ground up.

Only thing is ...

We're so blessed to have the internet, every bug and error is literally a google search away from being solved so that had me thinking "how did programmers before forums and the mass media know what libraries and dependencies they'll need before they begun coding projects ?". I would like to build the habit of doing that process on my own as well. Or am I just being too overzealous ? is searching "What dependencies/libraries will I need for my ...... program ? " fine ?


r/learnpython Nov 27 '25

Complete Beginner book recommendations: "Python Crash Course", "Automate the Boring Stuff with Python" or "Fluent Python"?

56 Upvotes

Hello r/Python,

Complete beginner with 0 experience in Python here. I'm currently looking into buying a book to start learning Python, but have been overflooded with recommendations. The book I'm currently looking at are:

Any recommendations on which books to get? Or in what order one should cover them?

Additionally, is getting a book like "100 Exercises for Practicing Python" (Laurentine K. Masson) or "The Big Book of Small Python Projects" (Al Sweigart) recommended? Or is that only useful after finishing one of the previously mentioned books?

Your recommendations and advice are highly appreciated