r/learnprogramming • • 29d ago

Python What are the best ways to learn Python online?

6 Upvotes

I've seen people talking about websites that are made to learn Python. What are the best resources/websites to learn the fundamentals of Python and learn how to use it?

r/learnprogramming • • Oct 22 '26

Python Best way to modify a list while iterating?

3 Upvotes

I've learned that modifying a list while looping over it can cause elements to be skipped or unexpected behavior. What are the best practices for handling cases where I need to add, remove, or modify elements during iteration?

Do you usually iterate over a copy, create a new list, or use another approach?

r/learnprogramming • • Apr 11 '23

Python Big Python Project for Starters?

100 Upvotes

So im curently kinda bored with python because every project I started is being done fast or its not exiting enough to continue working on the project. Could you give me a example for a good big project for beginners that actually has a practical use later. In my opinion the urge to continue working on a project when someone gives you the task rather than giving it yourself. thx

r/learnprogramming • • Feb 27 '24

Python In your opinion, what is the most underated python function?

36 Upvotes

Preferably a niche function but a common one is fine as well if you think it is underated, all answers are welcome! I just started learning python on Codecademy so I would love to hear what answers you guys have so that I can check each of them out and experiment with them :) For myself, I just learnt about zip() and I love it, i think it's really helpful, just a shame that the data points it combines are stored as tuples.

r/learnprogramming • • Jan 31 '23

Python Why is it important to use virtual environments for Python projects but not for other languages, such as C++, R, etc.?

116 Upvotes

If I understand correctly, the reason for using separate environments is so that different versions of the same library don't interfere with each other, as some projects may require particular versions of specific libraries. Or you might even have some libraries that only work with earlier versions of Python, etc. That makes sense. My question is, why is something that's apparently only relevant to Python? I never heard about using virtual environments with R, C, C++, or any other programming language. Why is there not an issue with different versions of libraries potentially interfering with each other in R, for example, but there is with Python?

r/learnprogramming • • Jul 12 '26

Python Im stuck standing

0 Upvotes

i've been working on this certification going on 3 weeks now which is crazy. i can't figure out why i keep getting caught up.

im building a Budgeting app for freeCodeCamp:

these are the final requirements:

You should have a function outside the Category class named create_spend_chart(categories) that takes a list of categories and returns a bar-chart string. To build the chart:

  • Start with the title Percentage spent by category.
  • Calculate percentages from withdrawals only and not from deposits. The percentage should be the percentage of the amount spent for each category to the total spent for all categories (rounded down to the nearest 10).
  • Label the y-axis from 100 down to 0 in steps of 10.
  • Use o characters for the bars.
  • Include a horizontal line two spaces past the last bar.
  • Write category names vertically below the bar.

This function will be tested with up to four categories.

it looks like its printing all of the categories added up as a float, i tried to get a sum() too, but it said its not iterable, i dont know how to separate it by the category. the math for percentages is simple enough to do, but i dont see where i can write the code yet and i can re-use the code from an rpg character maker i made to show the graph, but im stuck standing.

i need help with this code, but i also feel deeply there's something flawed with the way i'm approaching learning it, if its taken me this long to figure it out. i see others in my same position on the certification, making the code broken straight down to math instead of even using functions and passing it.

im not exactly sure what, but i was hoping some experienced programmers could help me in the right direction, i tend to hop head first into things so i think i might be missing something fundamental.

here is the code:

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []


    def deposit(self, amount, description=""):
        self.ledger.append({"amount": amount, "description": description})


    def withdraw(self, amount, description=""):
        if self.check_funds(amount):
            self.ledger.append({"amount": -amount, "description": description})
            return True
        else:
            return False


    def get_balance(self):
        balance = 0
        for transaction in self.ledger:
            balance += transaction['amount']    
        return balance


    def check_funds(self, amount):
        return amount <= self.get_balance()


    def transfer(self, amount, destination_category):
        if self.check_funds(amount):
            self.withdraw(amount, f"Transfer to {destination_category.name}")
            destination_category.deposit(amount, f"Transfer from {self.name}")
            return True
        else:
            return False
    def __str__(self):
        
            method = '\n'.join(f"{transaction['description']:23.23}{transaction['amount']:>7.2f}" for transaction in self.ledger )
            return f"{self.name.center(30,'*')}\n{method}\nTotal: {self.get_balance()}"


def spreadsheet(*categories):
    for category in categories:
        print(category)
        print()


def create_spend_chart(*categories):
    print('Percentage spent by category\n')
    total_withdraw = 0
    for category in categories:
        for transaction in category.ledger:
            if transaction['amount'] < 0:
                total_withdraw += transaction['amount']
                print(total_withdraw)
                
    
    


food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
clothing.deposit(1000)
clothing.withdraw(100)
clothing.withdraw(30.14)
spreadsheet(food, clothing)
create_spend_chart(food, clothing)

r/learnprogramming • • Mar 14 '23

Python Is learning by taking apart open source projects a good way to learn?

8 Upvotes

I'm yet another beginner who is stuck after finishing the basic courses. I've worked professionally as a data analyst, comfortable with writing basic Python and advanced SQL. I want to up my game as a programmer, and I thought "just jump in and try contributing to open source projects" would be a great way.

However, I find that there's a gap in my knowledge. I have no clue how to find the entry points of a typical Python project on github. So I'm kinda stuck. This made me think: "Are there any project owners / contributors who stream as they work?"

In particular, if they regularly do a "Here's how to find the entry points to this program, and here's how to do various trace calls to follow how the program works. Now we can start working on the issues queue, here's how I would attack this problem."

Is this a realistic / good way to overcome the gap? Any suggestions?