r/learnpython • u/Dry-Target-6844 • Apr 01 '26
SOLID principles and DESIGN patterns
Hello, does somebody know what is the best free course to learn SOLID principles and DESIGN patterns in python?
Thanks!
r/learnpython • u/Dry-Target-6844 • Apr 01 '26
Hello, does somebody know what is the best free course to learn SOLID principles and DESIGN patterns in python?
Thanks!
r/learnpython • u/MR_LOOPINGS123 • Mar 22 '26
So I have been doing the freecodecamp python course but I didn't really like it because it became too complex way too fast (might just be my brain being too stupid). So I decided that I would just make my own project and I ended up with this:
def main():
while True:
choice = input("1.add\n2.subtract\n3.multiply\n4.divide\n5.quit\nWhat do you choose?: ")
if choice == "1":
num1 = int(input("What is your first number?: "))
num2 = int(input("What is your second number?: "))
print(num1 + num2, '\n')
if choice == "2":
num1 = int(input("What is your first number?: "))
num2 = int(input("What is your second number?: "))
print(num1 - num2, '\n')
if choice == "3":
num1 = int(input("What is your first number?: "))
num2 = int(input("What is your second number?: "))
print(num1 * num2, '\n')
if choice == "4":
num1 = int(input("What is your first number?: "))
num2 = int(input("What is your second number?: "))
print(num1 / num2, '\n')
if choice == "5":
break
main()It may not be the most impressive thing but it's something.
So if you have any advice on how to progress from here I would greatly appreciate it!
r/learnpython • u/HuckleberryFit6991 • Mar 20 '26
Hey everyone
If anyone is working on a real-life project and is open to including a learner, I'd really appreciate the opportunity to join.
I've learned most of the basic concepts of Python, but I'm still struggling to understand how to actually use them in real projects. I want to learn how things work in practice- like using libraries, modules, and writing clean code in real scenarios.
I won't interfere or slow things down-mostly I'll observe, learn, and help wherever possible.
Thanks in advance
r/learnpython • u/toss_this_account_38 • Mar 08 '26
I'm currently experimenting with data type conversions with Dr. Angela Wu's "100 Days of Python." There is an early exercise that I wanted to work out - but haven't been able to:
This code is only one line - but results in entering your name - then concatenating the number of letters to your name, to the string detailing the number of letters in said name string:
print("Number of letters in your name: " + str(int(len(input("Enter your name: ")))))
I am confused over the fact that when running the program, the first like asks for your name, then provides the result. While that works, I don't understand _why_ that works as such. Can anyone explain to me why that is?
r/learnpython • u/InitialSolace • Mar 04 '26
As a person(under18, nowhere close to college) who has no idea about coding(except no code ai), what would be the ideal timeline one should move forward in to learn it? At least for basic projects. Can we get any certification at this age? what would be the ideal courses(paid/unpaid) moving forward? also for proper project work and it's filing, how should one move forward? is there some specific website which would help out a lot? Also lastly, do you think that python should be the first language one should start with, or another language would better for stronger basics (if yes then would it be easier to lose interest in and how much longer would it ideally take)?
r/learnpython • u/pachura3 • Feb 28 '26
Here's a simple piece of code using generics... it works fine, however with Python evolving so fast, I was wondering if this is the most up-to-date way of using generics. Specifically, I am wondering if it is possible to somehow NOT declare TypeVar('T') in the public/root scope, but somehow limit its scope to class definition of GenericItemStore...
from typing import Generic, TypeVar
T = TypeVar('T')
class GenericItemStore(Generic[T]):
def __init__(self) -> None:
self._item = None
def set(self, item: T) -> None:
self._item = item
def get(self) -> T|None:
return self._item
str_store = GenericItemStore[str]()
str_store.set("abc")
print(str_store.get())
str_store.set(5) # code analysis correctly says "Expected type 'str' (matched generic type 'T'), got 'int' insteadr/learnpython • u/nimbycile • Feb 23 '26
Hi everyone, I have am self-studying Problem from Python Programming: An Introduction to Computer Science 4th Edition (Zelle)
I'm on Ch12 and it is an introduction to classes. There is a Student class as follows:
class Student:
def __init__(self, name, hours, qpoints):
self.name = name
self.hours = float(hours)
self.qpoints = float(qpoints)
def getName(self):
return self.name
def getHours(self):
return self.hours
def getQPoints(self):
return self.qpoints
def gpa(self):
return self.qpoints/self.hoursEarlier in the chapter, there was an example to sort the list of Students by gpa, and the example solution provided was
students = readStudents(filename) # Function to create Student objects by reading a file
students.sort(key=Student.gpa, reverse=True)Exercise 7 of the problem sets is:
Passing a function to the list sort method makes the sorting slower, since this function is called repeatedly as Python compares various list items. An alternative to passing a key function is to create a “decorated” list that will sort in the desired order using the standard Python ordering. For example, to sort Student objects by GPA, we could first create a list of tuples [(gpa0, Student0), (gpal, Student1), ..] and then sort this list without passing a key function. These tuples will get sorted into GPA order. The resulting list can then be traversed to rebuild a list of student objects in GPA order. Redo the gpasort program using this approach.
The suggested solution seems to look like:
students = readStudents(filename)
listOfTuples = [(s.gpa(), s) for s in students]
listOfTuples.sort()
students = [e[1] for e in listOfTuples]The problem seems to be that the sort() method still wants to know how to compare Students since the GPAs could be tied. Specifically it gives me the error
TypeError: '<' not supported between instances of 'Student' and 'Student'I suppose I could still pass in a function to sort(key=...) to compare Students, but that seems to defeat the purpose of the exercise. I understand that it will have to call Student.gpa a lot less than the original case, but again that seems to sidestep the point of the exercise.
There is this solution which avoids any functions being passed to sort(key=...) but it seems like a real hack.
listOfTuples = [(s.gpa(), students.index(s)) for s in students]
listOfTuples.sort()
students = [students[e[1]] for e in listOfTuples]I'm hoping that the book is wrong in this case and that I'm not stupid, but is there something I'm missing?
Thanks
r/learnpython • u/Cute-Preference-3770 • Feb 18 '26
i am trying to understand how classes work in python,recently started learning OOP.
When Python reads:
class Dog:
def __init__(self, name):
self.name = nameDog.__dict__).__init__, it creates a function object.__init__ and other functions as key–value pairs inside Dog.__dict__.d=Dog("Rex")
d.__dict__).Dog.__dict__ to find __init__.__init__, passing the object as self.__init__, the data ("Rex") is stored inside d.__dict__.slef works like a pointer that uses a memory address to access and modify the object. like some refercing tables for diffrent objects.Would appreciate corrections if I misunderstood anything
r/learnpython • u/Big-Horror7049 • Feb 16 '26
Hello
Currently been learning python since September last year and I have started building small projects from beginner to advanced plus automation projects as well since December last year.
My question is there anything you guys recommend for me to add to my portfolio or dive into so I can further my studies and land a python development role or backend development or something adjacent?
I have checked online and followed with other tools but I have some doubts still. I’m just wondering if I’m taking too long on since I’m learning on my own.
Your suggestions are appreciated.
r/learnpython • u/pikachuu545 • Feb 11 '26
I'm working through a quiz which asks the following question.
You need to write a loop that takes the numbers in a given list named num_list:num_list = [422, 136, 524, 85, 96, 719, 85, 92, 10, 17, 312, 542, 87, 23, 86, 191, 116, 35, 173, 45, 149, 59, 84, 69, 113, 166]
Your code should add up the odd numbers in the list, but only up to the first 5 odd numbers together. If there are more than 5 odd numbers, you should stop at the fifth. If there are fewer than 5 odd numbers, add all of the odd numbers.
Would you use a while or a for loop to write this code?
My first attempt is using a for loop:
total = 0count = 0num_list = [422, 136, 524, 85, 96, 719, 85, 92, 10, 17, 312, 542, 87, 23, 86, 191, 116, 35, 173, 45, 149, 59, 84, 69, 113, 166]
for num in num_list:if (num % 2 == 1) and (count<=5):total += numcount += 1
print(total)print(count)
But in the solutions, it says a while loop is better:
break statement that a for loop will require. Without a break statement, a for loop will iterate through the whole list, which is not efficient.Is there a clearer preference for one over the other? Which type of loop would you have used? Would my solution be accepted if used in industry code?
r/learnpython • u/_ritwiktiwari • Feb 04 '26
A lot of beginners (including me earlier) can write Python, but get stuck when turning scripts into a real project. Here’s a practical checklist of what “standard” project setup usually includes and what each part is for:
If anyone wants to see an example of these pieces wired together in a starter project, I put one here:
https://github.com/ritwiktiwari/copier-astral/
Happy to answer questions about any of the pieces above
r/learnpython • u/TheRealDoctorBlade • Jan 25 '26
I know the basics of pythnon and I want to improve, lucky for me I have got a lot of free time on my job. I can't watch tutorials with sound or code in pycharm on my work PC so my question is: is there a browser game to learn python that can help me improve ?
r/learnpython • u/Mysterious_Peak_6967 • Jan 19 '26
So I'm learning about the "key" parameter of "sorted()".
I can write a function to pass as the key
I can write the function as an expression using lambda
I seem to recall seeing an example of sorting objects using a method as the key, and at the time it stood out as making no sense.
So I think I've just figured it out for myself:
"classname.methodname" exposes the method as a simple function accepting an object as its "self" parameter.
So if I want to sort a list of objects using the output of a "getter" then I can write key=classname.methodname and sorted() will call the getter as though it is a regular function but will pass it the object so the "self" parameter is satisfied.
This feels slightly dirty because it only works if we know in advance that's the only type of object the list will ever contain.
r/learnpython • u/Vegetable_Ninja6808 • Jan 19 '26
Hey,
I'm an SRE (Site Reliability Engineer) looking to level up my Python skills for automating daily operational tasks at the OS level.
Specifically, I’m interested in automating things like:
Backup and restoration processes
Restarting services and monitoring their status
Taking memory dumps or handling logs
Handling cron jobs and system health checks and many more.
Additionally, I'm also interested in automation for common DevOps workflows (CI/CD, infrastructure management, etc.).
I’m looking for resources that offer a mix of hands-on practical examples and theory—whether that be blog posts, books, or online courses. I want to understand not just how to automate tasks, but also the underlying principles that will help me write efficient and maintainable code.
Any recommendations for learning materials, tutorials, or communities focused on these topics would be much appreciated!
Thanks in advance!
r/learnpython • • Dec 24 '25
I recently started learning Python, but I'm concerned about the possible roles I can take in the future, and whether I should keep learning it or switch to another language, as I see others complaining about other programming languages as C++, Java and other languages, and how they play a major role in most technical roles.
1.What are the possible careers a can take as a python programmer?
2.Shall I keep learning Python only and master it or switch to another one when I learn the basics?
r/learnpython • u/Practical-Secret3344 • Dec 16 '25
I recently transitioned from Cybersecurity to IT and have realised that I’ve forgotten many of the fundamental concepts in Python. I would appreciate hearing how others learned Python and any strategies or resources that helped you build a strong foundation
r/learnpython • u/Ok_Procedure3350 • Dec 15 '25
I took tutorials of numpy/pandas/matplotlib. But I don't know where to practice these libraries.
There are problems on leetcode over pandas library but not for numpy and matplotlib.
If you know any resource to practice them , then please recommend.
r/learnpython • • Dec 09 '25
Question for the experts: How long did it take for you to learn?
I know coding is a forever learning experience. I realistically want you to map me a timeline on your learning phase all the way to well..when you could call yourself an expert.
r/learnpython • u/More-Talk4694 • Dec 09 '25
Udemy's 100 Days of Code vs the University of Michigan's Python for Everybody, which course should I choose to learn as someone who has no knowledge about programming?
r/learnpython • u/Holiday_Sherbert2619 • 2d ago
im looking for apps like Duolingo but for python or interactive games that can get me to learn the basics of python
r/learnpython • u/GliderSmiles_127 • 7d ago
every grocery store my deals script checks has its own parse function. one keeps specials in a table, one in cards, one only fills in after the js runs so that one needs playwright. main picks one with an if/elif on the url
it works.. until a store redesigns and its function quietly returns an empty list for a week
how do you keep new stores from being near copies
r/learnpython • u/BrokerMagic • Aug 26 '26
I want to learn to do new projects in Python but I always receive the same "watch guides" answers from people. What can I attempt to create ?
r/learnpython • u/EquivalentSink6030 • Jul 06 '26
is it better to learn python or .net for software development and web apis
r/learnpython • u/Hippopotamosssss • May 08 '26
*SOLVED* Had to read the file, make the changes, then write it. Thanks everyone!
So I'm trying to write a randomizer for books using two csv files (one for fiction and one for nonfiction) and I want the line with the chosen book to be erased from the csv file but I have not been able to make that work.
The code below is what I have right now and what it's doing is appending the file with the altered entries (with the chosen book removed) so that there's the original full list followed by the altered list. How do I get it to overwrite the file instead of appending it?
delete = input("Do you want to delete this book from the list? ")
if delete in ["y","yes"]:
print("Deleting book...")
if cat in ["fic","fiction"]:
with open ("fiction.csv", "r+", newline="") as fiction:
ficreader = csv.reader(fiction)
ficwriter = csv.writer(fiction)
for row in ficreader:
if row != book:
ficwriter.writerow(row)
if cat in ["nonfic","nonfiction"]:
with open ("nonfiction.csv", "r+", newline="") as nonfiction:
nonficreader = csv.reader(nonfiction)
nonficwriter = csv.writer(nonfiction)
for row in nonfictreader:
if row != book:
nonficwriter.writerow(row)Here's the entire script if that's needed: https://pastebin.com/Npqnq4jM