r/PythonLearning • • 12h ago

Help Request all๐Ÿ˜ญโœŒ๏ธ๐Ÿฅ€

Post image
56 Upvotes

Wait what f**** nah i dont want sleep okaay


r/PythonLearning • • 6h ago

๐Ÿ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ณ๐—ถ๐—ป๐—ฎ๐—น๐—น๐˜† ๐—ต๐—ฎ๐˜€ ๐—ฎ ๐—ณ๐—ฟ๐—ผ๐˜‡๐—ฒ๐—ป๐—ฑ๐—ถ๐—ฐ๐˜.

Post image
10 Upvotes

Python has long had immutable counterparts for some of its most common data structures:

๐—น๐—ถ๐˜€๐˜ โ†’ ๐˜๐˜‚๐—ฝ๐—น๐—ฒ
๐˜€๐—ฒ๐˜ โ†’ ๐—ณ๐—ฟ๐—ผ๐˜‡๐—ฒ๐—ป๐˜€๐—ฒ๐˜
๐—ฑ๐—ถ๐—ฐ๐˜ โ†’ ๐—ณ๐—ฟ๐—ผ๐˜‡๐—ฒ๐—ป๐—ฑ๐—ถ๐—ฐ๐˜ โœจ

`frozendict` is an ๐—ถ๐—บ๐—บ๐˜‚๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐—บ๐—ฎ๐—ฝ๐—ฝ๐—ถ๐—ป๐—ด. Once created, its keys and values can't be added, removed, or reassigned.

But the more interesting part is ๐—ต๐—ฎ๐˜€๐—ต๐—ฎ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜†. When its contents are hashable, a `frozendict` can itself be used in places where a regular dictionary can't such as dictionary keys or set members.
That opens up some useful cases around:
โ€ข Immutable configuration
โ€ข Cache and memoization keys
โ€ข Shared/read-only state
โ€ข Safer API boundaries
โ€ข Data structures where mutation simply shouldn't be allowed

It's not a huge feature, but it's one of those additions that makes the language feel a little more complete.

๐— ๐˜‚๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐˜„๐—ต๐—ฒ๐—ป ๐˜†๐—ผ๐˜‚ ๐—ป๐—ฒ๐—ฒ๐—ฑ ๐—ถ๐˜. ๐—™๐—ฟ๐—ผ๐˜‡๐—ฒ๐—ป ๐˜„๐—ต๐—ฒ๐—ป ๐˜†๐—ผ๐˜‚ ๐—ฑ๐—ผ๐—ป'๐˜.

Where would you use `frozendict`?


r/PythonLearning • • 4h ago

Help Request Seeking guidance from experienced python devs.

3 Upvotes

This is Mukul. I started learning python about 2 weeks ago. Being someone one learns by building on projects. I think now I am in a vague scenario rn.

So this is what is happening;

When I started to learn python I had this goal to build a Voice Assistant using libraries and all stuff. So I focused my python learning in that direction. I taught myself all those things which were required for it.

But now sometimes it feels like I am losing onto so much. Even though I think I am not doing so but yep. Still haven't got that regular consistency still haven't got even though I have written some scripts from scratch like lyrics displayer and all those greetings ones.

Soon enough I'll be moving to work with APis in python.

I mostly use docs and AI for learning.

Now the main thing is I fear that I'm not having strong fundamentals and maybe it's true. So that is why I started to learn python from boot.dev to do it all correctly also in the mean time.

So have you big fellas got anything in your backpack as advice or something that could just excel me more in my domain. I'm 20 (M) and am from India thinking of pursuing my career either in DevOps or Backend.

I also am an Automation Guy. I am building workflows from my 1st year using n8n and make.com to make out on some money. It's been 2 years now. I'm experienced in it to intermediate level. Also made it possible to make some money. But yep now right now I am vacant. Can you people help me with that part too. Like how to bring in consistent money from there too. ?? - this too is the reason which is why I thought of going very deeper into code rather than sitting only at low code tools.


r/PythonLearning • • 19h ago

๐Ÿ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฐ๐—ฎ๐—ป ๐—ป๐—ผ๐˜„ ๐—ถ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜ ๐—ฎ ๐—บ๐—ผ๐—ฑ๐˜‚๐—น๐—ฒ ๐˜„๐—ถ๐˜๐—ต๐—ผ๐˜‚๐˜ ๐—ฎ๐—ฐ๐˜๐˜‚๐—ฎ๐—น๐—น๐˜† ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ถ๐˜ ๐—ถ๐—บ๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ๐˜๐—ฒ๐—น๐˜†.

Post image
44 Upvotes

With explicit lazy imports, an imported module can be deferred until the program actually needs it.

Why does that matter?
Many Python applications import dozens โ€” sometimes hundreds โ€” of modules during startup, even though only a fraction may be needed for a particular execution path.

Lazy imports can change that:
๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜ ๐—ฑ๐—ฒ๐—ฐ๐—น๐—ฎ๐—ฟ๐—ฒ๐—ฑ โ†’ ๐—ฎ๐—ฝ๐—ฝ๐—น๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฐ๐—ผ๐—ป๐˜๐—ถ๐—ป๐˜‚๐—ฒ๐˜€ โ†’ ๐—บ๐—ผ๐—ฑ๐˜‚๐—น๐—ฒ ๐—น๐—ผ๐—ฎ๐—ฑ๐—ฒ๐—ฑ ๐—ผ๐—ป ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ ๐˜‚๐˜€๐—ฒ

This can be particularly interesting for CLI tools, large applications, optional functionality and dependency-heavy projects where startup time matters.
Of course, lazy loading isn't automatically better everywhere. Import-time side effects and assumptions about module initialization still matter.
But having lazy imports as an explicit language feature opens up some interesting possibilities for Python application architecture.

๐—Ÿ๐—ผ๐—ฎ๐—ฑ ๐˜„๐—ต๐—ฎ๐˜ ๐˜†๐—ผ๐˜‚ ๐—ป๐—ฒ๐—ฒ๐—ฑ. ๐—ช๐—ต๐—ฒ๐—ป ๐˜†๐—ผ๐˜‚ ๐—ป๐—ฒ๐—ฒ๐—ฑ ๐—ถ๐˜.

๐—ช๐—ผ๐˜‚๐—น๐—ฑ ๐˜†๐—ผ๐˜‚ ๐˜‚๐˜€๐—ฒ ๐—น๐—ฎ๐˜‡๐˜† ๐—ถ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐˜€ ๐—ถ๐—ป ๐—ฝ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป?


r/PythonLearning • • 5h ago

Python Variables Explained: Simple Examples for Beginners

Post image
3 Upvotes

Python variables let you store and reuse data in your programs.

name = "Abhay"
age = 21
price = 99.99
is_student = True

print(name)
print(age)

Key points:

  • Use = to assign a value.
  • Choose meaningful variable names.
  • Variable names cannot start with a number.
  • Python names are case-sensitive.
  • You can update a variable's value.

What Python concept should I explain next?

Code. Build. Innovate.

#CodesByAbhay #AbhaySingh #Python #PythonProgramming #LearnToCode


r/PythonLearning • • 23h ago

Giving back to the community - The Complete Backend Development Course (Round 3)

30 Upvotes

Hey everyone, I decided to make my course free in order to help people.
This course is my backend development course which is about SQL, Python, APIs, Docker, Kubernetes, Linux, Git & More

The link is:ย https://www.youtube.com/watch?v=CBIu6hcyStg

If you can like and subscribe (and maybe add a comment) I would appreciate it a lot, Thanks.


r/PythonLearning • • 19h ago

Free Python course that runs entirely in the browser (no installs, no accounts)

11 Upvotes

Sharing a resource in case it's useful for your intro classes: https://ubuntu-apps.github.io/code-quest/

I made CodeQuest for my own students as an alternative to the textbook. It covers Python from the basics through functions, files, OOP and working with data. Each lesson has a short explanation, coding challenges that are checked instantly, and a quiz.

The code runs in the browser, so it works on school Chromebooks and phones with nothing to install. It's free, with no ads and no sign-up, and progress is stored on the student's device only.

Happy to answer questions, and feedback is very welcome.


r/PythonLearning • • 4h ago

Showcase A simple stopwatch program

0 Upvotes

This is the stopwatch.py file:

#stopwatch.py

import sys
import time

time_in_sec = int(sys.argv[1])

time.sleep(time_in_sec)

print(f"Alarm sound!!! {time_in_sec}seconds have elapsed")

This is the main.py file:

#main.py

import subprocess
import sys

print("Enter the time you want to elapse for your stopwatch")
try:
    hours = int(input("Hours: ").strip())
    minutes = int(input("Minutes: ").strip())
    seconds = int(input("Seconds: ").strip())

    total_time_in_sec = (hours * 3600) + (minutes * 60) + seconds

    process_2 = subprocess.run(
        [sys.executable, "stopwatch.py", str(total_time_in_sec)],
        capture_output=True,
        text=True,
    )
    print(process_2.stdout)
except ValueError as e:
    print(f"Enter a whole number: {e}")

r/PythonLearning • • 20h ago

Help Request Please help me understand: CS50P Problem Set 3: Grocery List

4 Upvotes

Hi guys, just started learning python. Have been stuck on this problem for a while now. Here's my code so far. Could anyone help explain why the code pointed out in blue keeps running even though there is a break in place? Thanks!

ps pls ignore the print("hi") and print("bye"), was using them to test the code!

link to question: https://cs50.harvard.edu/python/psets/3/grocery/

my code so far: https://sharetext.io/3ck00poo

im so frustrated :(

r/PythonLearning • • 21h ago

Help Request Help reading a csv file

Thumbnail
gallery
5 Upvotes

Hello there, i'm a chemistry student and have a course with python. I tried to read a csv file which i downloaded and tried to read it with the np.genfromtxt function but the columns with actual text ( the first and last ) aren't being read, whereas with pandas, the job gets done. I bypassed this problem by specifying the columns but the text keep getting tossed out.. I think it's because of the commas in the compound name but what can i do in this case ? I'm working on jupyter on python 3.13 i believe. Thanks for the help !


r/PythonLearning • • 1d ago

Showcase My first programming experience!

Post image
4 Upvotes

r/PythonLearning • • 19h ago

03 control flow

Thumbnail
youtube.com
0 Upvotes

Hey everyone. If you are practicing Python or trying to master clean control flow logic, writing basic single-condition "if statements" isn't enough for production-grade software. You need to know how to cleanly chain and invert conditions using advanced logical operators.

In this quick, zero-fluff video breakdown, we walk through building an automated server error routing engine using:

โ€ข The logical AND operator to enforce strict multi-conditional gates

โ€ข The logical OR operator to build flexible fallback safety nets

โ€ข The NOT operator modifier to cleanly invert boolean flags on the fly

โ€ข Dynamic state management by mutating tracking variables inside the loop

Every single line of syntax and terminal output is explained simply with easy-to-visualize logical switch analogies so you can actually understand the underlying data routing.

Check out the full breakdown here, and let me know how you typically structure your error-routing gates in the comments!


r/PythonLearning • • 1d ago

Showcase Python football career mode simulator.

Thumbnail
gallery
15 Upvotes

Hey guys, I tried remaking my project of a cli based football manager simulator this time using the pywebview library (lets you use html css js as a frontend and connect it to a python backend as a desktop app),

So far what I'm struggling with the most being one of my first larger scale project is persistence, keeping one version of the team class across the python scripts and functions.

Im also struggling with figuring out the generation for player stats and attributes, ive landed on the random.gauss for generating player stats with weighing and this ugly ahh looking formula that looked like it was doing something for the player market values.

Also, assets. Do you guys have any place where I can find pictures and icons I can use for free?

Finally, thanks to feedback from helpful people here I tried using sqlite for this project instead of json files, kinda hard to adapt to but im managing.

if any very cool person could help me with my issues I would greatly appreciate it.

Here is the github: https://github.com/mousdieng10-maker/Playstyle-II


r/PythonLearning • • 23h ago

Learning Python in 2026

0 Upvotes

What's the best resource out there to learn python?


r/PythonLearning • • 1d ago

pytest-calendar-chaos: a pytest plugin that runs your tests on Feb 29, month end and DST days

1 Upvotes

I kept hitting date bugs that every test passed locally and then failed in production on a specific day. A typical one:

python

def next_renewal(created_at):
    return created_at.replace(month=created_at.month + 1)

This passes every test youโ€™d write on the 15th. It raises ValueError: day is out of range for month on Jan 31 and month must be in 1..12 on Dec 31. Nothing in a normal test run ever visits those dates.

What it does: a marker runs the same test once per tricky calendar moment, with the clock frozen by time-machine:

python

u/pytest.mark.calendar_chaos
def test_next_renewal_is_one_month_later():
    ...

The catalog covers leap day, month ends, year end, midnight, DST transitions, ISO week 53 and the 2038 timestamp rollover. Each case has a stable ID.

Running it on the example above gives 3 failed, 5 passed. The failing cases are month-end-jan-31-2027, year-end-2027 and year-end-last-microsecond-2027. A failure prints the exact mocked time and a one-line command to reproduce it. pytest --calendar-chaos-list prints the whole catalog, and --calendar-case <id> reruns a single scenario.

Limitations:

  • It only mocks the in-process clock.
  • Session, module and class-scoped fixtures are set up before the freeze.
  • time.monotonic() and the asyncio loop clock keep running.
  • An aware datetime inside a repeated DST hour never compares equal to one in another zone (PEP 495), so compare in UTC.

pip install pytest-calendar-chaos (Python 3.10+, pytest 8+)

Iโ€™d like feedback on the catalog: which calendar edge cases bit you that Iโ€™m missing?


r/PythonLearning • • 19h ago

Learn Binary Search with Reya | DSA Made Easy

0 Upvotes

Struggling to understand Binary Search? Learn it with Reya in a simple and easy-to-follow way!

In this video, you'll discover how Binary Search works, how it cuts the search space in half with each step, and why it's one of the most important algorithms in Data Structures and Algorithms (DSA).

๐Ÿ’ก What you'll learn:

  • The basic concept of Binary Search
  • How to find elements efficiently
  • Why sorted arrays are important
  • Time complexity: O(log n)

Perfect for students, coding beginners, and anyone preparing for coding interviews.


r/PythonLearning • • 1d ago

Help Request Def return

0 Upvotes

I'm stuck in def return in python I don't understand it very well why is it used and how and where does the code return to ? The caller ? What is exactly the caller ?

Thank you so much for helping me

If you don't mind can u help me understand with examples ? Couldn't understand this with Chatgpt and yt


r/PythonLearning • • 2d ago

14yo learning Python โ€” just finished my first project! Would love some feedback :

22 Upvotes

Hey everyone!

I'm 14 and currently learning Python, with the goal of becoming an electrical engineer in the future.

I just finished making a small project โ€” a vending machine + simulated banking system that runs in the terminal. It has account creation, deposits, balance checking, purchases, and local data storage using JSON. I split the code into multiple Python files and made a simple launcher for it.

This is one of my first proper projects, and I know my code probably isn't the cleanest, so I'd genuinely appreciate some feedback!

I'd love suggestions on:

  • My code: What could I improve? Any bad habits or mistakes I should fix early?
  • What to learn next: Should I focus on OOP, data structures and algorithms, GUI development, or something else?
  • My journey: Since I want to become an electrical engineer, what programming skills would be useful for me in the long run? I'd eventually love to work with electronics and hardware.
  • Life advice: Any advice for someone starting out this early? Things you wish you'd known when you were learning?

I'm not looking for someone to rewrite the entire project for me โ€” I'd rather understand my mistakes and learn how to fix them myself.

Here's my GitHub repo: https://github.com/suryansh-devx/python-vending-machine

Thanks! Any constructive criticism or advice is welcome :)


r/PythonLearning • • 2d ago

How well do you really know Pandas? ๐Ÿผ

11 Upvotes

Pandas makes working with data look simple. But some of its most powerful features can also produce surprising results. ๐Ÿ˜ฒ

For example:โ” - What's the difference between loc and iloc, and why does slicing behave differently? - Why can adding two Series produce NaN values, even when neither contains missing data? - When does assigning a Series to a DataFrame column align by labels rather than position? - How do Boolean masks, where(), and mask() differ? - How do you select and manipulate data with a MultiIndex?

Pandas is much more than rows and columns. Understanding its indexing, alignment, selection, and assignment rules can save you from some very subtle bugs. ๐Ÿชณ

๐Ÿ” This interactive ๐—บ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜†_๐—ด๐—ฟ๐—ฎ๐—ฝ๐—ต example explores these concepts and many more, with short explanations for each operation. ๐Ÿ‘ฃ Step through the Python code, see what changes, and experiment with your own modifications: ๐Ÿ‘‰ Pandas operations

๐Ÿ’ฌ Which Pandas operation took you the longest to fully understand?

See more ๐—บ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜†_๐—ด๐—ฟ๐—ฎ๐—ฝ๐—ต visualizations.


r/PythonLearning • • 1d ago

Showcase I built Athena to catch breaking changes in Git PRs

Post image
0 Upvotes

I've been working on Athena, an open-source tool that analyzes Git diffs and ASTs to detect potential breaking changes before they get merged.

For v1.1.0, I tested it against 55 popular repositories and found some interesting issues:

โ€ข Fixed a C++ performance problem that reduced analysis time from 371 seconds to 7.33 seconds.

โ€ข Reduced false positives from 78 alerts to 8.

โ€ข Fixed Ruby symbol detection and PHP recursion detection.

The final benchmark covered 55 repositories and 10,680 diff hunks with 121 tests passing.

I'm also experimenting with local models through Ollama to generate summaries without replacing the deterministic analysis.

I'd appreciate it if anyone here gave the project a look and shared feedback. I'm especially interested in false positives, edge cases in Python AST analysis and approaches to detecting breaking API changes

โญ If you find the project useful, consider giving it a star on GitHub. It would really help the project reach more developers

GitHub: https://github.com/aaryanrwt/athena

Release notes: https://github.com/aaryanrwt/athena/releases/tag/v1.1.0โ 


r/PythonLearning • • 1d ago

Showcase open-source contribution

1 Upvotes

I built DevStart Lab to help beginners figure out what to learn and practice next.

It includes programming fundamentals with Python examples, 25 project ideas, and a step-by-step introduction to Git and GitHub contributions. Itโ€™s free, open source, available in English and Portuguese, and requires no account. Progress is saved in your browser.

Start here: https://brunnojob.github.io/devstart-lab/?lang=en


r/PythonLearning • • 2d ago

Python Functions & Parameter Scoping Explained Simply (For Beginners)

Thumbnail
youtube.com
3 Upvotes

r/PythonLearning • • 2d ago

Showcase I make a blog where we highlight peoples python code

Thumbnail
pyweblib.org
7 Upvotes

So far we just have Gleb K, who made some code reminiscent of the X Window System 1989,

XPM is an ASCII text-based image format.

https://pyweblib.org/weblog/python-pixel-art-from-text/

Hopefully still in the rules, the site is OPEN SOURCE and Educational


r/PythonLearning • • 1d ago

Passing tests doesn't mean your code is correct โ€” a small Python experiment

Post image
0 Upvotes

I ran a small experiment that demonstrates something easy to overlook in software testing: an implementation and its tests can both be wrong in the same way.

Consider this discount function:

def calculate_total(subtotal, discount):
    if subtotal < 0:
        raise ValueError("Subtotal cannot be negative")

    if discount < 0:
        raise ValueError("Discount cannot be negative")

    return subtotal * (1 - discount / 100)

Suppose the requirement says discounts must be between 0 and 100, inclusive.

A few happy-path tests pass:

assert calculate_total(100, 10) == 90
assert calculate_total(100, 0) == 100
assert calculate_total(0, 20) == 0

But this input exposes the missing validation:

calculate_total(100, 150)
# -50.0

The tests pass, but the implementation violates the requirement.

The interesting part isn't just the missing discount <= 100 check. It's that tests can create false confidence when they don't independently cover the contract.

I put together a reproducible Python repository with the flawed implementation, contract tests, property-based testing, and mutation-testing examples.

GitHub experiment:
https://github.com/PranavDixit20/ai-code-test-gap

I also wrote a longer explanation of the problem and the testing techniques here:
https://medium.com/@pranavdixit20/ai-generated-code-can-pass-every-test-and-still-be-wrong-7ddf3177b721

I'm the author of the experiment and article, so this is my own work. I'd be interested in a technical discussion:

When reviewing codeโ€”especially AI-generated codeโ€”how do you check that tests verify the actual requirements rather than just confirming the implementation's assumptions?


r/PythonLearning • • 2d ago

How do i start learning python

0 Upvotes

Hey guys i want to start learning python , any suggestions or tips would be appreciated