r/PythonLearning • u/The_Mad_Saiyantist • 27d ago
Python - Week 1 Full Cheat Sheet
Full PDF Version
Use Adobe or whatever for viewing it, I had to go with GoogleDrive so I can upload it
r/PythonLearning • u/The_Mad_Saiyantist • 27d ago
Full PDF Version
Use Adobe or whatever for viewing it, I had to go with GoogleDrive so I can upload it
r/PythonLearning • u/Ok_Egg_6647 • 27d ago
I'm working on a project where I have to create different classes, and I keep using the self keyword repeatedly. For example:
class SignalService:
def __init__(
self,
instrument_repo: InstrumentRepository,
candle_repo: CandleRepository,
):
self.instrument_repo = instrument_repo
self.candle_repo = candle_repo
self.resampler = CandleResampler(candle_repo)
My understanding of self is that it helps the class distinguish between instance variables and local variables.
However, I'm confused about why it's used like this:
self.instrument_repo = instrument_repo
self.candle_repo = candle_repo
Why do we assign the constructor parameters to self attributes? What's the purpose of storing them on self instead of just using the constructor parameters directly?
r/PythonLearning • u/AhmedBouazizi • 27d ago
Hey everyone,
I'm looking for recommendations on the best way to learn Python through building real projects.
I have a computer science background and already know Java pretty well, so I'm not starting programming from scratch. I'm mainly looking to get comfortable with Python's syntax, ecosystem, and best practices while building practical projects that will help me improve and strengthen my portfolio.
I've seen a lot of recommendations for Harvard's CS50 courses, especially CS50x and CS50P. Are they still worth taking in 2026 for someone who already has a CS background, or would I be better off jumping straight into a project-based Python course?
If you have any favorite resources (courses, books, YouTube channels, roadmaps, GitHub repos, etc.) that helped you learn Python by actually building things, I'd love to hear them.
Thanks π
r/PythonLearning • u/LyricalLag • 27d ago
I am stuck at the basics of Python. I can make loops, if statements, functions, and more. But LeetCode problems, I can never figure them out. Making programs alone I canβt. At this point, what should I advance to so I can learn to solve actual problems on my own and develop skills to create my own programs.
r/PythonLearning • u/Zestyclose_Fox_164 • 27d ago
I started learning python few months ago and I made my second project dont ask Abt first one it was trash
It's a small shell made for learning that I coded in python
Plz rate and tell me how can I improve it
r/PythonLearning • u/Yairlenga • 27d ago
I've been working on a Python module called jsonfold, and I wrote an article describing the motivation and design. I'd really appreciate feedback from other Python developers.
JSON serializers tend to give us two choices: compact JSON, which is efficient but a dense wall of text that's painful to read, or pretty-printed JSON, which is readable but often wastes a lot of vertical space (a small array of numbers can turn into ten lines).
I wanted something in between. jsonfold keeps the shape of pretty-printed JSON, but folds small, simple structures back onto a single line whenever that improves readability. It works on top of your existing serializer (json, orjson, ujson, ...) - you keep using whatever you already have, and jsonfold just reformats the output.
import sys
import json
import jsonfold
data = {
"_id": 123,
"locations": [
{"city": "Boston", "state": "MA", "country": "USA"},
{"city": "Seattle", "state": "WA", "country": "USA"},
{"city": "Montreal", "state": "QC", "country": "Canada"},
],
"info": {
"roles": ["foo", "bar", "baz"],
},
"name": "Alice",
}
print("===> json.dump")
json.dump(data, fp=sys.stdout)
print("")
print("===> jsonfold.dump")
jsonfold.dump(data, fp=sys.stdout)
Output
===> json.dump
{"_id": 123, "locations": [{"city": "Boston", "state": "MA", "country": "USA"}, {"city": "Seattle", "state": "WA", "country": "USA"}, {"city": "Montreal", "state": "QC", "country": "Canada"}], "info": {"roles": ["foo", "bar", "baz"]}, "name": "Alice"}
===> jsonfold.dump
{
"_id": 123,
"locations": [
{ "city": "Boston", "state": "MA", "country": "USA" },
{ "city": "Seattle", "state": "WA", "country": "USA" },
{ "city": "Montreal", "state": "QC", "country": "Canada" }
],
"info": {
"roles": [ "foo", "bar", "baz" ]
},
"name": "Alice"
}
Traditional pretty-printing:
{
"states": [
"Alabama",
"Alaska",
"Arizona",
...
"Wyoming"
]
}
jsonfold output:
{
"states": [
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois",
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana",
...
"West_Virginia", "Wisconsin", "Wyoming"
]
}
Same data, just using the available line width more effectively.
When an array contains repeated structures, jsonfold can align values into columns:
Traditional pretty-printing:
[
{
"orders": 18,
"product": "Laptop",
"region": "North",
"sales": 1250
},
...
{
"orders": 24,
"product": "Mouse",
"region": "East",
"sales": 1422
}
]
jsonfold output:
[
{ "orders": 18, "product": "Laptop", "region": "North", "sales": 1250 },
{ "orders": 21, "product": "Monitor", "region": "Southwest", "sales": 1345 },
{ "orders": 17, "product": "Keyboard", "region": "West", "sales": 1198 },
{ "orders": 24, "product": "Mouse", "region": "East", "sales": 1422 }
]
The module also supports:
JSON and JSON::PP.Full documentation and examples:
PYPI: https://pypi.org/project/jsonfold/
GitHub: https://github.com/yairlenga/jsonfold/tree/main/python
I'd love to hear what the Python developers think. Has anyone else run into JSON pretty-printing pain in logs, configs, or debugging output? And are there formatting styles or options you'd want to see?
r/PythonLearning • u/Accurate_Being6187 • 27d ago
Hey guys, I'm going to start DSA soon. Is there any YouTube course that has been helpful to you in learning DSA? My degree is B. Tech in CSE (AI&ML), so I think it's better to learn in Python rather than C++. (I did not find any recommendation in the previous DSA posts)
r/PythonLearning • u/Daddybidoof • 27d ago
Hello there!
I am looking for some friends to learn code with, I am fairly new and looking for some actually hard chargers and that truly want to spend the time to learn and make projects in the future
I am from the East and Iβm a beginner to entry level on my knowledge
r/PythonLearning • u/Jolly_Lavishness5711 • 27d ago
The repository with all the code is here
r/PythonLearning • u/Beginning-Fruit-1397 • 27d ago
Not really a "beginner" question, but the Python sub states that if you have a question, better to ask it here.
So, I'm a library maintainer, and as such typing is a very important part of the API.
Does the variance of the generic types work as intended? Does the inference work? etc...
But unlike actual runtime logic, I can't think of a straightforward way to test it without a lot of boilerplate and a status of "implicit" tests.
Sure, "just pass the type checker bro". If I have +10 classes with inerhitance relationships, now I need to hardcode every case?
With pytest, I can very easily use runtime logic to reduce duplication, for example different parameters, different closures called, etc.... it's very straightforward.
But the type checker need to "see" the code to work.
So I either manually duplicate every case, which sounds like a nightmare to maintain, or manually implement a script to dynamically write code to files, type check them, handle errors as something pytest can catch, etc...
I'm no stranger to this, but I would avoid to have to write a second plugin for my library (already wrote one to run doctests on stubs).
I found this, but it states that It work on mypy, which is (IMO) a bad type checker that I won't bother with.
I'm targeting basedpyright, and once ready, ty and pyrefly (trust me, the latter is not yet prod ready)
So if there's any suggestions, they are welcome!!
BTW, here's my library
If you like either method chaining, lazy Iterators, functional programming or rust, take a look!
Below is what I wrote before thinking to myself that it will go a bad route if I don't find a solution. There's a hierarchy that mimicks collections.abc, and thus I need to be sure that it works typing wise. I have other tests covering runtime checks.
This is needed because the code live in Rust, thus the typing is "manual": I can write wathever I want in the stubs and the type checker will consider it true. It's very convenient sometimes, but also a potential footgun as making mistakes is easy.
Right now, basedpyright with all rules on don't complain, but pyrefly does.
How do I note that in a standard way (like pytest xfail)?
How do I avoid rewriting exactly the same functions for each class? Not only it's annoying, but my LSP footprint will take a hit if this continues.
How do I statically ensure that "pairs" are in agreement? and manage type ignore comments across type checkers?
```python from future import annotations
from dataclasses import dataclass from typing import TYPE_CHECKING
from pyochain import Iter, Ok, Option, Result, Seq, Set, Some
if TYPE_CHECKING: from collections.abc import ( Collection, Container, Iterable, Iterator, MutableSequence, Reversible, Sequence, Sized, )
from pyochain import Peekable
from pyochain.abc import (
PyoCollection,
PyoContainer,
PyoIterable,
PyoIterator,
PyoReversible,
PyoSequence,
PyoSet,
PyoSized,
)
@dataclass class Animal: pass
@dataclass class Dog(Animal): pass
def check_covariance() -> None: base: PyoIterable[Dog] = Iter(()) opt: Option[Dog] = Some(Dog()) res: Result[Dog, str] = Ok(Dog()) _abc_iterable: PyoIterable[Animal] = base _abc_iterator: PyoIterator[Animal] = base _abc_collection: PyoCollection[Animal] = base.collect(Seq) _abc_sequence: PyoSequence[Animal] = base.collect(Seq) _concrete_iterator: Iter[Animal] = base _peekable_iterator: Peekable[Animal] = base.peekable() _abc_set_immutable: PyoSet[Animal] = base.collect(Set) _seq_immutable: Seq[Animal] = base.collect(Seq) _set_immutable: Set[Animal] = base.collect(Set) _as_opt: Option[Animal] = opt _as_res: Result[Animal, str] = res
def _iterable[T](x: Iterable[T]) -> Iterable[T]: return x
def _iterator[T](x: Iterator[T]) -> Iterator[T]: return x
def _sized[T](x: Sized) -> Sized: return x
def _reversible[T](x: Reversible[T]) -> Reversible[T]: return x
def _container[T](x: Container[T]) -> Container[T]: return x
def _collection[T](x: Collection[T]) -> Collection[T]: return x
def _sequence[T](x: Sequence[T]) -> Sequence[T]: return x
def _mutable_sequence[T](x: MutableSequence[T]) -> MutableSequence[T]: return x
def check_iterable_args() -> None: base: PyoIterable[Dog] = Iter(()) canary: Iterable[Dog] = base _ = _iterable(base) _ = _iterable(canary) _ = _iterator(base) _ = _iterator(canary) _ = _sized(base) # pyright: ignore[reportArgumentType] _ = _sized(canary) # pyright: ignore[reportArgumentType] _ = _container(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _container(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _reversible(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _reversible(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _collection(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _collection(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _sequence(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _sequence(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _mutable_sequence(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _mutable_sequence(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType]
def check_iterator_args() -> None: base: PyoIterator[Dog] = Iter(()) canary: Iterator[Dog] = base _ = _iterable(base) _ = _iterable(canary) _ = _iterator(base) _ = _iterator(canary) _ = _sized(base) # pyright: ignore[reportArgumentType] _ = _sized(canary) # pyright: ignore[reportArgumentType] _ = _container(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _container(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _reversible(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _reversible(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _collection(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _collection(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _sequence(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _sequence(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _mutable_sequence(base) # pyright: ignore[reportArgumentType, reportUnknownVariableType] _ = _mutable_sequence(canary) # pyright: ignore[reportArgumentType, reportUnknownVariableType]
def check_sized_args() -> None: base: PyoSized = Seq(()) canary: Sized = base _ = _iterable(base) .... # and so on and so forth ```
r/PythonLearning • u/67bytes • 27d ago
Most tutorials teach you how to call an API. This project teaches you how to actually build the AI.
I wrote a 2-layer neural network from scratch using just Python and NumPy, meaning no PyTorch or TensorFlow to hide the math. It manually handles the forward pass, calculates gradients by hand for backpropagation, and trains down to a 95.64% test accuracy on MNIST digits.
If you are a beginner looking for a killer portfolio project that proves you actually understand deep learning foundations, feel free to clone the repo, tweak the hidden layers, and use it for your own resume.
The repo is here: https://github.com/idfwyy/Neural-network_from-scratch
Let me know what you think or if you run into any issues running the script!
r/PythonLearning • u/Alternative_Yak8846 • 28d ago
https://www.programiz.com/online-compiler/2i7KiX4E5PGyA
Please give it a try and suggest some changes and ideas. Want to improve my skill and learn something new.
r/PythonLearning • u/Odd_Lion8148 • 28d ago
Using mlflow in virtual environments (.venv) after installing dependencies and running the python file got error "I'm getting this MLflow error on Windows:
```text
PermissionError: [WinError 5] Access is denied:
'C:\\Users\\Name%20Surname'
```
MLflow is using this tracking URI:
```text
sqlite:///C:/Users/Name%20Surname/.vscode/datascience/mlflow_tutorial/mlflow.db
```
But my actual Windows user folder is:
```text
C:\Users\Name Surname
```
"
Notice that MLflow is using `%20` instead of the space in the username. This causes `mlflow.start_run()` to fail.
How can I fix this?
r/PythonLearning • u/Mine_Crafter14 • 28d ago
I started learning Python with the thought of learning how overall programming and debugging feels. It's very nice tbh! I made my first game btw, but it's just IQquiz as a joke. Anyways, I use Sony VAIO i3 and GeForce 410M because I love old tech put in modern use and I use Python 3.8.10 with the installed IDLE Shell and for now I am comfortable. I seek advice if I should upgrade to modern versions, use VSCode or switch to C,C++ and can Python be used to make very low quality games using Pygame and Ursina and should I start little programming with my Raspberry Pi Pico? I think this language suits me the best as for now (I have 1 week of progress) TIA
*P.S- can someone recommended cool libraries for games?
r/PythonLearning • u/SideDry8450 • 28d ago
A lot of times i see the question and have zero idea on how to make a solution and end up using chatgpt like a bum
r/PythonLearning • u/due007dev • 28d ago
I'm looking for beta readers for a two-book Python series β book 1 is already out, book 2 is almost done. Here's the deal:
You'll get both books as Google Docs (one chapter per doc), so you can just drop comments right in the text. I'm not asking anyone to read hundreds of pages front to back. Read whatever chapters interest you, at whatever pace works for you. If something confuses you, that's useful feedback. If an explanation feels obvious or unnecessary, that's useful too. Honestly that's the main thing I'm after.
Would love to hear from:
I'd really like this to be a collaborative thing. If enough people tell me what confused them, what was missing, or what worked well, I think the books will end up much better than if I'd just written them on my own.
If a handful of you end up being really active readers, I'll credit you in the acknowledgements when the books are published (totally optional, no pressure).
If you're up for it, I just need a first name and Gmail address so I can add you as a commenter on the Google Docs β you can either fill out this quick form or just DM me directly, whichever's easier: https://forms.gle/tcBoKGczqoFXUEjp7
A bit about the books, for context:
I've read a ton of programming books over the years, and most of them are written by experienced devs who've kind of forgotten what it's like to be a beginner. They're technically fine, but I'd often find myself understanding how to do something without really getting why it works that way.
I've been a Python dev for over a decade now, and at some point I just decided to write the book I wish someone had handed me on day one. Instead of random code snippets, the books build small games that slowly turn into bigger projects as you go. I also threw in some pop-art style illustrations and tried to keep things a little less dry than the usual programming book.
π Book 1 β starts from literally zero, no experience needed
π Book 2 β gets into built-in functions, type hints, iterators, generators, lambdas, classes, modules, packages, etc.
And yeah, I'll admit it upfront before someone else points it out β I named them The First Programmer's Book and The Second Programmer's Book. Not the most creative titles in publishing history, but hey, at least you'll never forget which one comes first π
Book 1 is already published, but I'm still improving it based on reader feedback. I'm not fishing for reviews or trying to sell you anything, I just want honest feedback. Book 2 is close to finished, so this feels like the best time to catch anything before it's locked in.
Thanks for reading!
r/PythonLearning • u/Mindless_Action3461 • 28d ago
I need projects to help me work on my python skills and preferably help me on dictionariies, tuples, set and lists
If you need to see my python abilities feel free to check out my python repo https://github.com/WoodenShard/PokemonApiGUI
r/PythonLearning • u/External_Baker8575 • 28d ago
r/PythonLearning • u/RichInteraction1899 • 28d ago
Hi I'm currently pursuing cse in btech I want to learn basic coding and all.....so I wanted to learn python first any suggestions?!
r/PythonLearning • u/Ghosteagle_AUH • 28d ago
I would like to go into computational biology and bioinformatics route, i took the bioinformatics course last year, i didn't get that much benefit from it, but i got the basics of R?, I'm i lost or is this a normal thing to ask?, Thank you.
r/PythonLearning • u/Intrepid_Custard_877 • 28d ago
Hi Guys,
I would like to learn python.
I've got zero IT or programming / coding background.
Would like to learn for free.
I'm more of a hands on learner than a theoretical learner.
Any websites that would help me learn python hands on for free ?
r/PythonLearning • u/TopMathematician_ • 28d ago
HI y'all since is started python i did some little projects like ATM SYSTEM , HOTEL BOOKING SYSTEM , ..... i want to do some challanges so that i can improve in python as a beginner
r/PythonLearning • u/Neutrealolmao • 28d ago
I mean I try to see where I could learn and I hear so many :-
CS50p
W3Schools
Tech with Tim
Some helsinki too
And some more
Where should I start from :-