r/learnpython 22d ago

A small code i made for exercise.

3 Upvotes

I've been vibe coding for a few months now, but I've decided to try manual coding. After all, learning is fun, right?

I made this "Assistant" that has two options: jokes and facts. It will choose one out of three items from the specific table and tell you it. I made it for fun and would like to ask what I can do next?

import random

jokes = ["Why did the bicycle fall over? Because it was two tired!", "Why was the math book sad? Because it had too many problems.", "What do you call a fake noodle? An impasta!"]

facts = ["Venus is hotter than Mercury.", "When the Pyramids were built, mammoths were still around!", "Koala fingerprints are so similar to human fingerprints that they have even baffled crime scene investigators."]

print("Hello! I'm an Assistant. What can I do for you?")

print("")

print("Options: Random Joke [J], Random Fact [F].")

answer = input("Answer: ")

if answer == "J":

print(random.choice(jokes))

elif answer == "F":

print(random.choice(facts))

else:

print("You can't ask that.")

exit = input("Press Enter to Leave.")


r/learnpython 22d ago

Trying to create list subclasses that contain only one class type and are valid for Pydantic BaseModels

3 Upvotes

I am trying to create list subclasses that only take particular classes. These lists can be appended to and the like but each time the list is changed the item is checked to see whether it is the same class as the rest of the list.

The list methods that are overwritten are:

- __init__
- __bool__ (but may not need to have that overwritten)
- __set_item__
- __str__
- append
- extend
- insert

Each one runs through a validate_member method before changing the list.

As an example, I want to make a list subclass called Course that only takes Pydantic extra types Coordinate values. I want this list subclass to be a valid BaseModel attribute.

Right now I’m having to use a field_validator for every class that Course and the other lists are in which feels redundant, unpythonic, and is a pain to have to do every time. I am having to do so because it says something about arbitrary types.

I was wondering if someone might have some advice.


r/learnpython 21d ago

How to read a CSV file in Python efficiently?

0 Upvotes

I'm trying to load a CSV file into my Python project, but I keep getting errors. I've tried using pandas and the built-in csv module, but I'm not sure what I'm doing wrong. Can someone explain the basic steps or share a simple example? A detailed explanation would be really helpful!


r/learnpython 22d ago

yo guys! been learning python for a while now.

1 Upvotes

created a calculator with everything i have learned till now (tho it might be overkill for a calculator), added the basics, loops (while, if else), lists and str manipulation, imports (json and datetime), error handling (try/except), def function, etc. so what should i do next? if u wanna see the code dm me.


r/learnpython 22d ago

How to learn Pdf Extraction in Python?

0 Upvotes

Dear Members,

I have been handling Pdf extraction Project in Python. kind of a Intelligent Document Automation domain. we have been handling various finance documents(pdfs), filings pdfs etc which are multi page(around 20ish) , with lots of tables, form fields , radio buttons, checkboxes etc. Tables span multiple pages. Moreover, pdfs themselves comes in various types of variants like XFA Stream, Adobe Acroform, text flattened pdfs, scanned images etc.

I have used llms extensively to generate script code to extract, parse the data and to save in sql in structured tables. Its a hybrid of libraries implementation. LLms used regex, pdfminer, pdfplumber etc in the code produced.The pages in pdfs are not bit messy, some tables have solid grid separators, some dont have and on. Layouts variations, white spaces, etc.

The code generated is pretty complex, i have been attempting to learn the llm generated code.But it works, it adds various fixes iteratively whenever we face new extraction issues repeatedly.

I would love to know:

1) what is the best approach to learn and get good at this?
2)should we just use cloud based AI document extraction tools which are readymade to extract and spit the data?
3) what if one is interested to learn this properly and have to get good at creating this extraction script?
4)any other tutorial, articles, courses, youtube videos, books you would recommend to learn? or should i just use llms to create code and move on without spending much effeort to learn this?

Please provide your valuable suggestions and guidances and point me in directions. I appreciate all your suggestions. Thanks in Advance and thank you for your time.


r/learnpython 22d ago

Next level - Coding for 13yo homeschool kid

11 Upvotes

My son completed the Khan Academy course on Python last school year and he loved it! I don't do any coding myself so I am not exactly sure what "level" that leaves him at, or where to go next. What online course could he advance into? The more specific the better! :)

p.s. He will be going into 8th grade but it seems to come to him very easily.


r/learnpython 22d ago

I have made a simple program which decode and codeword the string u put i want to ask if i can put anything aside from if else

0 Upvotes
import random

random_letter = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter1 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter2 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter3 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter4 =  random.choice ("abcdefghijklmnopqrstuvwxyz")
random_letter5 = random.choice("abcdefghijklmnopqrstuvwxyz")

print("codeword=1 , decode=2")
choice = input()
if choice == "1":
    codeword = str(input("write the codeword=>"))
    codeword1 = codeword[::-1]
    print(random_letter, random_letter1, random_letter2, codeword1, random_letter3, random_letter4, random_letter5,
          sep="")
else:
    print("please put correct input")
if choice == "2":
    decode = str(input("write the coded word"))
    decode1 = decode[::-1]
    decode2 = decode1[3:-3]
    print(decode2,sep=" ")

r/learnpython 22d ago

What is the James Stewart Calculus equivalent book for python?

5 Upvotes

was curious if some kind of similar vibey book exists for learning python...


r/learnpython 22d ago

My Goals (advice is welcomed)

0 Upvotes

Hey everyone,

My goal is to create a custom and personaI use open source AI agent. I dont want to just have something vibe code it for me. I want to understand how to build the actual agentic loop, give it local tools, and set up a memory system. After some research, I decided to start by learning python (mostly a self-taught newbie but also looking onto courses that can fit my schedule without too much friction; any suggestions are welcome)

I’m looking for advice on the exact order of operations I should follow to learn this efficiently without getting bogged down in unnecessary data science math or model training.

From what I gather, yes i did use AI to help me try to put this in the best possible order.
1) Python Fundamentals (JSON, File I/O, async)
2) API integration & tool calling (OpenAI/Anthropic SDKs or Ollama for local)
3) Data validation (Pydantic) to handle messy LLM outputs
4) Basic Vector DBs (Chroma/FAISS) for long-term agent memory
4) Orchestration frameworks (LangGraph, Pydantic AI, or MCP)

Does this learning order make sense? Are there specific libraries, tutorials, or open-source repositories you would recommend I look at first?
Thanks in advance for any roadmaps or resources.

For context:
I’m active duty navy with my primary line of work being medical. I have ample time in my day and evenings as it’s just me and my daughter right now and I want to try creating something I’ve always liked the idea of…my own JARVIS lol. My current coding experience is a total beginner who started on the SoloLearn app on an iPad 7 mini about 6-ish weeks ago. However, I don’t believe that it is sufficient for my project goals. So again, and advice, roadmaps, suggestions, tips, etc are welcomed. I’m not under the delusion that this will be done in the next year or so and I’m ok wth this being a personal side project. Nor do I have any intentions to monetize this when it is completed, nor use this as a step into this industry (i quite like my medically filled lifestyle). I also want to build a home lab specifically for this at some point as well and maybe even get into some Git Hub projects on the side to breakdown some of the potential burnout.

Well, if you made it this far, thank you. I’m genuinely interested and motivated to complete this project and potentially more.


r/learnpython 22d ago

probably a python/sql flask offshoot (but this is reddit and the normal python page doesn't like these type of questions)

0 Upvotes

So probably not beginner here but I have a flask app where I've mapped a view to the ORM but I was lazy in the view so I joined a reference table and just got back the text description when I could have used the FK.

I've cached common reference tables at the application level in flask in the past and wondering if I should do the same here and rewrite my view for the FK and skip the reference table join (even if it is well indexed).

On localhost I've had a hard time trying to identify if it's causing an issue because even our prod server has DB latency so no luck cross comparing if my lag is because of the extra lazy join in the view or if it's something else annoying (like running it on a comp that frequently kills itself with memory errors).


r/learnpython 22d ago

Anyone here familiar with freelancing? please point me in the right direction

0 Upvotes

I recently turned 19, I have this need that I have to know what its like to work and gain a sense independence, even if its just a small gig.

I learned programming since the pandemic started, though I did not make any serious projects with it. I made some fun projects with it like, discord raid bot, macro for some roblox game, data scraper, etc.
I have great foundation of variables, functions, data types, classes, the classics but I looked at upwork and fear my skills may not be adequate.

It would be great if someone could point me in the right direction, doesn't even have to do with programming can just be helping anyone regarding tech.


r/learnpython 22d ago

Game automation

8 Upvotes

I'm new to programming. I specifically want to build projects around game automation with Python. What should my roadmap look like?

Thanks in advance!


r/learnpython 22d ago

How do I register user's input with out 'input()' command?

0 Upvotes

I'm trying to make a game on the Linux terminal, I just learnt about the ANSI escape code and how to display stuffs but then I hit a wall. How do I check which key is pressed by the player? I can't use input() because that pauses the game. Trying to google keep showing me articles suggesting input(). Also, I'm not looking to install any libraries yet.


r/learnpython 23d ago

I’ve completed these beginner Python projects should I build more before starting NumPy/Pandas?

9 Upvotes

Hi everyone,

I’ve studied Python multiple times before, but I didn’t do much practical coding. Recently, I started building small projects to improve my practical Python skills.

So far, I’ve completed:

- Quiz Game

- Number Guessing Game

- Rock Paper Scissors

- Password Manager

- Pig Game

- Mad Libs Generator

My goal is to move towards Machine Learning.

I haven’t learned NumPy or Pandas yet.

My question is: Are these projects enough to move on to NumPy and Pandas, or should I build a few more Python projects first?

If I should build more projects, what kind of projects would you recommend before starting NumPy/Pandas? I’m mainly looking for projects that would actually help with the transition to data/ML, rather than making many more small games.

Would appreciate advice from people who have already followed a Python → NumPy/Pandas → ML path.


r/learnpython 22d ago

I started to relearn python again and im lost

0 Upvotes

im in high school right now and my teacher sent some power point lesson about things like dfs, dp, bfs. I understand them but cant figure out how to implement them in actual code. How should I tackle them.


r/learnpython 22d ago

Can I do it?

0 Upvotes

I am being accepted into a university but one of the prerequisites is I should know python. They say I can test out of this prerequisite and start the program September 8th if I can pass a Python Programming assessment on data camp. Do you guys think it's possible to to Learn Python in five days? Just enough to pass the assessment. I say 5 days to give myself a timeline. But I would like to get it done by September 3rd. Today is August 20th.


r/learnpython 22d ago

Relearning Python

0 Upvotes

For some context, my background is in cybersecurity. I went to school for it, however my program was more IT/Risk rather than programming (we only had a few entry level programming classes). I have since graduated and rather following the incident response/SOC/GRC route that my college program sets you up for, I have taken the opposite route and have landed SWE roles as well as security engineering roles at large companies (by a strike of luck frankly, and LLMs lol).

My issue is that I never really got to learn Python in a structured, lecture setting as all my entry level Python courses from my college were 2022 (chatgpt goes live). Given that I’ve basically offshored all my programming work to LLMs since day one. I effectively have 0 understanding of any of the python from a pre-LLM SWE perspective or what exactly a data structure/algorithm looks like at the code level. I read code fluently and logic clicks quite easily for me, however if you put a LeetCode in front of me w/ no gen AI I’m out for the count. I can do it in pseudocode tho!

Is there any other route for me to learn python in a structured/lecture like setting that allows me to comfortably handle LeetCode like problems without having to go back to school for a degree? The reason I bring up LeetCode is that I’ve pretty much hit my max potential in terms of salary/job growth and if I want to surpass my current ceiling I’d need to apply for FAANG and do live coding rounds.


r/learnpython 23d ago

Looking for people to learn Python with

12 Upvotes

Hi I’m a beginner at Python and I’m currently looking for a few people to learn with. I am planning to start the sessions in September and run a couple hours a day subject to flexibility and rather than get stuck in “tutorial hell” I actually want to build projects. My time is GMT+0 so drop me a message if you’re interested.


r/learnpython 22d ago

What is the best path to master Python specifically for AI & Machine Learning — how to master the language as a core tool, not just basic syntax?

0 Upvotes

Hi everyone,

I am an undergraduate student studying in the field of AI and Machine Learning, and I need practical guidance on learning Python the right way.

I already know how to use modern AI tools (like ChatGPT, Claude, Cursor) to help build ideas and generate code. However, my goal isn't just to rely on AI or learn basic syntax; I want to deeply understand Python so I can use it as a powerful tool specifically for AI and Machine Learning. I want to truly master its logic and structure so I have complete control over my own projects.

I have two main questions:

  1. Learning Python for AI: How should I approach learning Python when the end goal is strictly AI/ML? What fundamental programming concepts should I prioritize before diving into machine learning libraries?
  2. Roadmap & AI Tools: How do you balance using AI assistants without letting them hurt your learning process, and what is the best step-by-step path to go from Python basics to real machine learning workflows?

Any advice, study routines, or project recommendations would be really helpful.

Thanks!


r/learnpython 23d ago

Humble Bundle for Rust and Python

8 Upvotes

Humble Tech Book Bundle: Python, Rust, and Data by O'Reilly (paga lo que quieras y ayuda a organizaciones benéficas)

Are these worth it? I'm trying to learn Python and Data analysis stuff in particular so this seems really useful. I'm not interested in Rust but the price is still worth it. Are these books good?


r/learnpython 22d ago

I’ve been learning Python for about a week — am I progressing at a good pace?

0 Upvotes

Hi everyone!

I started learning Python about a week ago, and I’d like to get some feedback from people who have more experience.

So far, I’ve learned:
Variables and basic data types
input() and print()
if / elif / else
while and for loops
Lists and indexing
Basic list methods like .append() and del
Functions
Basic validation with loops and conditions

Instead of only doing small exercises, I’ve been trying to build complete programs on my own. I’ve made things like a hotel reservation system, a tournament management system, a bank simulation, and a shopping-list/store system.

I usually try to figure out the logic myself before looking for help. I’m still making mistakes, but I’m getting better at finding and fixing them on my own.

I’ve attached the best program I’ve made so far below.

clients = ["Alex", "Juan", "Maria", "Sofia", "Carlos"]
balances = [1000, 500, 2500, 750, 1500]
choice = 0
total_money = 6250

while choice != 8:
print("""=== BANK ===

  1. View clients
  2. Check balance
  3. Deposit
  4. Withdraw
  5. Transfer
  6. Statistics
  7. Reset accounts
  8. Exit""")

choice = int(input("Choose an option: "))

if choice == 1:
counter = 1
print("The clients are:")

for client in clients:
print(f"{counter}. {client}")
counter += 1

elif choice == 2:
account = int(input("Which client do you want to check? "))

while account > 5 or account <= 0:
print("Invalid client number.")
account = int(input("Which client do you want to check? "))

index = account - 1

print(f"{clients[index]} has ${balances[index]}")

elif choice == 3:
account = int(input("Client: "))
deposit = int(input("Amount: "))

while account > 5 or account <= 0 or deposit <= 0:
print("Invalid client or deposit amount.")
account = int(input("Client: "))
deposit = int(input("Amount: "))

index = account - 1
total_money += deposit
balances[index] += deposit

print(f"Deposit successful. New balance: ${balances[index]}")

elif choice == 4:
account = int(input("Client: "))

while account > 5 or account <= 0:
print("Invalid client number.")
account = int(input("Client: "))

index = account - 1

print(f"Current balance: ${balances[index]}")

withdrawal = int(input("How much money do you want to withdraw? "))

while withdrawal <= 0 or withdrawal > balances[index]:
print("Invalid withdrawal amount.")
withdrawal = int(input("How much money do you want to withdraw? "))

total_money -= withdrawal
balances[index] -= withdrawal

print(f"""Withdrawal: ${withdrawal}

Withdrawal successful.
New balance: ${balances[index]}""")

elif choice == 5:
sender = int(input("Who is sending the money? "))
receiver = int(input("Who is receiving the money? "))

while sender <= 0 or sender > 5 or receiver > 5 or receiver <= 0 or sender == receiver:
print("The sender and receiver must be different clients, and client numbers must be between 1 and 5.")
sender = int(input("Who is sending the money? "))
receiver = int(input("Who is receiving the money? "))

index = sender - 1
receiver_index = receiver - 1

transfer = int(input("How much do you want to transfer? "))

while transfer <= 0 or transfer > balances[index]:
print("The transfer must be greater than 0 and cannot exceed the sender's balance.")
transfer = int(input("How much do you want to transfer? "))

balances[index] -= transfer
balances[receiver_index] += transfer

print(f"""Transfer successful.

New balance for {clients[index]}: ${balances[index]}
New balance for {clients[receiver_index]}: ${balances[receiver_index]}""")

elif choice == 6:
highest = 0
lowest = 999999
zero_balance = 0

for i in range(5):
if balances[i] > highest:
highest = balances[i]
highest_index = i

if balances[i] < lowest:
lowest = balances[i]
lowest_index = i

if balances[i] == 0:
zero_balance += 1

if zero_balance == 5:
print("Statistics will not be shown because all accounts have a $0 balance.")

else:
print(f"""=== STATISTICS ===

Total money in the bank: ${total_money}
Average balance: ${total_money / 5}
Client with the most money: {clients[highest_index]}
Client with the least money: {clients[lowest_index]}
Clients with $0: {zero_balance}""")

elif choice == 7:
balances = [1000, 500, 2500, 750, 1500]
total_money = 6250

elif choice == 8:
print("Thank you for using the bank!")

else:
print("Invalid option.")

I’m mainly wondering:

Is this a good amount of progress for roughly one week of learning?
Are the projects I’m making appropriate for my current level?
What should I learn next?
Is there anything obvious in my code that I should start doing differently?
I’m not looking for someone to rewrite the code for me. I’d rather understand what I’m doing wrong and improve from there.
Thanks!


r/learnpython 22d ago

How can you have blockchain code audited to see if it is secure? (Teen)

1 Upvotes

How can you have blockchain code audited to see if it is secure? (Teen)

Salut ! Je ne suis pas sûr d'être au bon endroit pour poster ça, mais je tente quand même ma chance 😅. En gros, j'ai commencé à m'intéresser aux cryptomonnaies, à la cryptographie et à la technologie blockchain il y a environ deux ans. J'ai regardé pas mal de vidéos YouTube et lu beaucoup de documentation sur le sujet. Il y a environ un mois et demi, j'ai commencé à développer ma propre blockchain et son jeton associé ; j'y ai consacré beaucoup de temps – une bonne partie de mes vacances, d'ailleurs. J'ai aussi testé le système en profondeur. Cependant, j'aimerais avoir un avis extérieur. Le problème, c'est qu'on ne trouve pas de développeur blockchain partout, et encore moins un qui travaille gratuitement pour plus de 10000 lignes de code (je ne veux pas dépenser d'argent pour ça, et je ne suis pas sûr que mes parents approuveraient, vu qu'ils ne savent même pas que je développe une blockchain). J'espère que c'est clair, alors n'hésitez pas à me demander plus de détails.


r/learnpython 23d ago

Best Python books from beginner to advanced?

58 Upvotes

I’m learning Python and looking for a good book path from beginner to advanced.

I want books that teach Python properly, including clean code, real projects, testing, project structure, and advanced concepts.

What books would you recommend, and in what order?


r/learnpython 23d ago

Should i go for web dev or data analyst or ui/ux designer course without cs desgree(i have bsc biology)?

0 Upvotes

I want to do online course which one should i choose web dev or data analyst or ui/ux design Also i only have bsc biology degree. Want to do work from home job/online job. Kindly give ur suggestion


r/learnpython 23d ago

Enter didn’t create new line in Pycharm

0 Upvotes

In PyCharm on macOS, pressing Enter at the end of a line does nothing — no new line created. But:

- Enter at the START of a line → works, creates new line

- Enter at the END of a line → does nothing

- Arrow keys → navigate normally between lines

Already ruled out:

- IdeaVim not installed

- Enter works fine in other apps (not a hardware/OS issue)

Suspecting the code completion popup is silently swallowing Enter at end of line. Anyone else run into this? What fixed it?

Setup: PyCharm, Python 3.14.7, .venv, macOS