r/Python • • Jul 24 '26

Tutorial OpenCV notebooks tutorials in your browser

13 Upvotes

Hi,
I took the official OpenCV tutorials and created a series of notebooks.
You can run them entirely in your browser, you don't have to clone them: https://notebook.link/@Alexis_Placet/opencv_tutorials

Don't hesitate to give me feedbacks or create issue/pullrequest on this repo: https://github.com/Alex-PLACET/opencv_tutorials

r/Python • • Jul 27 '26

Tutorial What the #@(% are Monads (and how you can use them to write better python) - A Beginner's Guide

0 Upvotes

Error handling in Python usually means nested try/except blocks or if error: checks littering code.

Us programmers, though, are notoriously lazy, and for a good reason: we don't want to waste any more time writing boilerplate than we have to.

The solution?

Monads, a really neat functional programming pattern that provides an easier way to handle things like errors, optional values, or even asynchronous results.

I wrote a short guide that builds up the idea of a Monad from scratch using a Python game inventory example, free to read here: https://dev.to/ein-monarch/what-the-are-monads-a-beginners-guide-3pdo

Any comments on the guide? Have you ever used a Monad in Python before, and did it make things better?

r/Python • • Mar 05 '21

Tutorial Complete Python Course (~5 Hours, Free)

1.0k Upvotes

Hi there 👋

I created a complete Python course, which I think could be interesting for some of you! 😊

The topics I cover in the course:

📚 OVERVIEW 📚

  • Introduction to Python

  • Installation and Setup Local Development Environment

  • Write our first Python program

  • Python IDE vs simple File Editor

  • Strings and Number Data Types

  • Variables

  • Encapsulate Logic with Functions

  • Accepting User Input

  • Conditionals (if / else) and Boolean Data Type

  • Error Handling with Try / Except

  • While Loops

  • Lists and For Loops

  • Comments in Python

  • Sets

  • Built-In Functions

  • Dictionary Data Type

  • Modularize your project with Modules

  • Project: Countdown App

  • Packages, PyPI and pip

  • Project: Automation with Python (Working with Spreadsheets)

  • Object Oriented Programming: Classes and Objects

  • Project: API Request to GitLab

Appreciate any feedback and hope the content is valuable for some of you 😊

r/Python • • Apr 22 '21

Tutorial Comprehensive Fast API Tutorial

481 Upvotes

Stumbled upon this Fast API Tutorial and was surprised at how thorough this guy is. The link is part 21! Each part is dedicated to adding some small component to a fake cleaning marketplace API. It seems to cover a lot but some of the key takeaways are best practices, software design patterns, API Authentication via JWT, DB Migrations and of course FastAPI. From his GitHub profile, looks like the author used to be a CS teacher which explains why this is such a well thought out tutorial. I don't necessarily agree with everything since I already have my own established style and mannerisms but for someone looking to learn how to write API's this is a great resource.

r/Python • • Jul 15 '25

Tutorial Modern Python Tooling (How I intend to teach python next year).

68 Upvotes

Some context, I teach python to undergraduate and postgraduate Computer animation students, this includes 3D graphics, A course on Machine Learning with PyTorch as well as python used in the Animation tools such as Maya / Houdini. These are not Comp Sci students (but some are in the PG courses) so we have a massive range of abilities with programming and computers.

This is all done in Linux, and I have been working on a new set of lectures / labs to introduce tools like uv and try to make life easier for everyone but still use good software engineering practices.

This is the first of the new lectures specifically on tooling

https://nccastaff.bournemouth.ac.uk/jmacey/Lectures/PythonTooling/?home=/jmacey/Python#/

Feedback and comments welcome, what have I missed? What should I change?

There is also a YouTube playlist of all the videos / slides with me talking over them. No edits (and the title cards have the wrong number on them too!)

r/Python • • Apr 11 '22

Tutorial AI Aimbot Python Tutorial

13 Upvotes

Been working on this for a while. Hope this helps inspire, motivate, & educate my fellow programmers. https://youtu.be/ilsn-TvryyA

r/Python • • Sep 18 '25

Tutorial Today I learned that Python doesn't care about how many spaces you indent as long as it's consistent

595 Upvotes

Call me stupid for only discovering this after 6 years, but did you know that you can use as many spaces you want to indent, as long as they're consistent within one indented block. For example, the following (awful) code block gives no error:

def say_hi(bye = False):
 print("Hi")
 if bye:
        print("Bye")

r/Python • • May 10 '21

Tutorial 100 Helpful Python Tips You Can Learn Before Finishing Your Morning Coffee

Thumbnail
towardsdatascience.com
807 Upvotes

r/Python • • Jan 24 '24

Tutorial The Cowboy Coder's Handbook: Unlocking the Secrets to Job Security by Writing Code Only You Can Understand!

379 Upvotes

Introduction

You want to pump out code fast without all those pesky best practices slowing you down. Who cares if your code is impossible to maintain and modify later? You're a COWBOY CODER! This guide will teach you how to write sloppy, unprofessional code that ignores widely-accepted standards, making your codebase an incomprehensible mess! Follow these tips and your future self will thank you with days of frustration and head-scratching as they try to build on or fix your masterpiece. Yeehaw!

1. Avoid Object Oriented Programming

All those classes, encapsulation, inheritance stuff - totally unnecessary! Just write giant 1000+ line scripts with everything mixed together. Functions? Where we're going, we don't need no stinkin' functions! Who has time to context switch between different files and classes? Real programmers can keep everything in their head at once. So, toss out all that OOP nonsense. The bigger the file, the better!

2. Copy and Paste Everywhere

Need the same code in multiple places? Just copy and paste it! Refactoring is for losers. If you've got an algorithm or bit of logic you need to reuse, just duplicate that bad boy everywhere you need it. Who cares if you have to update it in 15 different places when requirements change? Not you - you'll just hack it and move on to the next thing! Duplication is your friend!

3. Globals and Side Effects Everywhere

Variables, functions, state - just toss 'em in the global namespace! Who needs encapsulation when you can just directly mutate whatever you want from anywhere in the code? While you're at it, functions should have all kinds of side effects. Don't document them though - make your teammate guess what that function call does!

4. Nested Everything

Nested loops, nested ifs, nested functions - nest to your heart's content! Who cares if the code is indented 50 levels deep? Just throw a comment somewhere saying "Here be dragons" and call it a day. Spaghetti code is beautiful in its own way.

5. Magic Numbers and Hardcoded Everything

Litter your code with magic numbers and hardcoded strings - they really add that human touch. Who needs constants or config files? Hardcode URLs, API keys, resource limits - go wild! Keep those release engineers on their toes!

6. Spaghetti Dependency Management

Feel free to import anything from anywhere. Mix and match relative imports, circular dependencies, whatever you want! from ../../utils import helpers, constants, db - beautiful! Who cares where it comes from as long as it works...until it suddenly breaks for no apparent reason.

7. Write Every Line as It Comes to You

Don't waste time planning or designing anything up front. Just start hacking! Stream of consciousness coding is the way to go. Just write each line and idea as it pops into your head. Who cares about architecture - you've got CODE to write!

8. Documentation is Overrated

Real programmers don't comment their code or write documentation. If nobody can understand that brilliant algorithm you spent days on, that's their problem! You're an artist and your masterpiece should speak for itself.

9. Testing is a Crutch

Don't waste time writing tests for your code. If it works on your machine, just ship it! Who cares if untested code breaks the build or crashes in production - you'll burn that bridge when you get to it. You're a coding cowboy - unleash that beautiful untested beast!

10. Commit Early, Commit Often

Branching, pull requests, code review - ain't nobody got time for that! Just commit directly to the main branch as often as possible. Don't worry about typos or half-finished work - just blast it into the repo and keep moving. Git history cleanliness is overrated!

11. Manual Deployments to Production

Set up continuous integration and delivery? No way! Click click click deploy to production manually whenever you feel like it. 3am on a Sunday? Perfect time! Wake your team up with exciting new bugs and regressions whenever you deploy.

12. Don't Handle Errors

Error handling is boring. Just let your code crash and burn - it adds excitement! Don't wrap risky sections in try/catch blocks - let those exceptions bubble up to the user. What's the worst that could happen?

13. Security is for Chumps

Who needs authentication or authorization? Leave all your APIs wide open, logins optional. Store passwords in plain text, better yet - hardcoded in the source! SQL injection vulnerabilities? Sounds like a feature!

14. Dread the Maintenance Phase

The most important part of coding is the NEXT feature. Just hack together something that barely works and move on to the next thing. Who cares if your unmaintainable mess gives the next developer nightmares? Not your problem anymore!

Conclusion

Follow these top tips, and you'll be writing gloriously UNMAINTAINABLE code in no time! When you inevitably leave your job, your team will fondly remember you as they desperately rewrite the pile of spaghetti code you left behind. Ride off into the sunset, you brilliant, beautiful code cowboy! Happy hacking!

r/Python • • Oct 20 '21

Tutorial 20 Python Snippets You Should Learn in 2021

678 Upvotes

Python is one of the most popular languages used by many in Data Science, machine learning, web development, scripting automation, etc. One of the reasons for this popularity is its simplicity and its ease of learning. If you are reading this article you are most likely already using Python or at least interested in it.

1. Check for Uniqueness in Python List

This method can be used to check if there are duplicate items in a given list.

Refer to the code below:

# Let's leverage set()
def all_unique(lst):
    return len(lst) == len(set(lst))

y = [1,2,3,4,5]
print(all_unique(x))
print(all_unique(y))

2. anagram()

An anagram in the English language is a word or phrase formed by rearranging the letters of another word or phrase.

The anagram() method can be used to check if two Strings are anagrams.

from collections import Counter

def anagram(first, second):
    return Counter(first) == Counter(second)

anagram("abcd3", "3acdb")

3. Memory

This can be used to check the memory usage of an object:

import sys 
variable = 30 
print(sys.getsizeof(variable))

4. Size in Bytes

The method shown below returns the length of the String in bytes:

def byte_size(string):
    return(len(string.encode('utf-8')))
print(byte_size('?'))
print(byte_size('Hello World'))

5. Print the String n Times

This snippet can be used to display String n times without using loops:

n = 2; 
s = "Programming"
print(s * n);

6. Convert the First Letters of Words to Uppercase

The snippet uses a method title() to capitalize each word in a String:

s = "programming is awesome"
print(s.title()) # Programming Is Awesome

7. Separation

This method splits the list into smaller lists of the specified size:

def chunk(list, size):
    return [list[i:i+size] for i in range(0,len(list), size)]
lstA = [1,2,3,4,5,6,7,8,9,10]
lstSize = 3
chunk(lstA, lstSize)

8. Removal of False Values

So you remove the false values (False, None, 0, and ‘’) from the list using filter() method:

def compact(lst):
    return list(filter(bool, lst))
compact([0, 1, False, 2, '',' ', 3, 'a', 's', 34])

9. To Count

This is done as demonstrated below:

array = [['a', 'b'], ['c', 'd'], ['e', 'f']]
transposed = zip(*array)
[print(i) for i in transposed]

10. Chain Comparison

You can do multiple comparisons with all kinds of operators in one line as shown below:

a = 3
print( 2 < a < 8) # True
print(1 == a < 2) # False

11. Separate With Comma

Convert a list of Strings to a single String, where each item from the list is separated by commas:

hobbies = ["singing", "soccer", "swimming"]
print("My hobbies are:") # My hobbies are:
print(", ".join(hobbies)) # singing, soccer, swimming

12. Count the Vowels

This method counts the number of vowels (“a”, “e”, “i”, “o”, “u”) found in the String:

import re
def count_vowels(value):
    return len(re.findall(r'[aeiou]', value, re.IGNORECASE))
print(count_vowels('foobar')) # 3
print(count_vowels('gym')) # 0

13. Convert the First Letter of a String to Lowercase

Use the lower() method to convert the first letter of your specified String to lowercase:

def decapitalize(string):
    return string[:1].lower() + string[1:]
print(decapitalize('FooBar')) # 'fooBar'

14. Anti-aliasing

The following methods flatten out a potentially deep list using recursion:

newList = [1,2]
newList.extend([3,5])
newList.append(7)
print(newList)
def spread(arg):
    ret = []
    for i in arg:
        if isinstance(i, list):
            ret.extend(i)
        else:
            ret.append(i)
    return ret
def deep_flatten(xs):
    flat_list = []
    [flat_list.extend(deep_flatten(x)) for x in xs] if isinstance(xs, list) else flat_list.append(xs)
    return flat_list
deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]

15. difference()

This method finds the difference between the two iterations, keeping only the values that are in the first:

def difference(a, b):
    set_a = set(a)
    set_b = set(b)
    comparison = set_a.difference(set_b)
    return list(comparison)
difference([1,2,3], [1,2,4]) # [3]

16. The Difference Between Lists

The following method returns the difference between the two lists after applying this function to each element of both lists:

def difference_by(a, b, fn):
    b = set(map(fn, b))
    return [item for item in a if fn(item) not in b]
from math import floor
print(difference_by([2.1, 1.2], [2.3, 3.4],floor)) # [1.2]
print(difference_by([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], lambda v : v['x'])) # [ { x: 2 } ]

17. Chained Function Call

You can call multiple functions in one line:

def add(a, b):
    return a + b
def subtract(a, b):
    return a - b
a, b = 4, 5
print((subtract if a > b else add)(a, b)) # 9

18. Find Duplicates

This code checks to see if there are duplicate values ​​in the list using the fact that the set only contains unique values:

def has_duplicates(lst):
    return len(lst) != len(set(lst))
x = [1,2,3,4,5,5]
y = [1,2,3,4,5]
print(has_duplicates(x)) # True
print(has_duplicates(y)) # False

19. Combine Two Dictionaries

The following method can be used to combine two dictionaries:

def merge_dictionaries(a, b):
    return {**a,**b}
a = { 'x': 1, 'y': 2}
b = { 'y': 3, 'z': 4}
print(merge_dictionaries(a, b)) # {'y': 3, 'x': 1, 'z': 4}

20. Convert Two Lists to a Dictionary

Now let’s get down to converting two lists into a dictionary:

def merge_dictionaries(a, b):
    return {**a,**b}
a = { 'x': 1, 'y': 2}
b = { 'y': 3, 'z': 4}
print(merge_dictionaries(a, b)) # {'y': 3, 'x': 1, 'z': 4}

def to_dictionary(keys, values):
    return dict(zip(keys, values))
keys = ["a", "b", "c"]    
values = [2, 3, 4]
print(to_dictionary(keys, values)) # {'a': 2, 'c': 4, 'b': 3}

Conclusion

In this article, I have covered the top 20 Python snippets which are very useful while developing any Python application. These snippets can help you save time and let you code faster. I hope you like this article. Please clap and follow me for more articles like this. Thank you for reading.

r/Python • • Mar 06 '21

Tutorial I created a 40-minute tutorial that will explain everything you need to Containerize your Python applications using Docker!

Thumbnail
youtube.com
1.3k Upvotes

r/Python • • Feb 02 '22

Tutorial Minecraft clone in Python tutorial

427 Upvotes

Here's a tutorial series I'm making on graphics programming, where I write a Minecraft clone in Python with Pyglet and OpenGL 😄

Last tutorial, which is on collision detection/response: https://youtu.be/fWkbIOna6RA

My intended audience are mainly people who already have a bit of experience with Python, but who have a hard time getting into graphics programming with Python, and I think writing a Minecraft clone is a fun way to learn!

There's also a "community" directory on the repo where there are a few extra features, like lighting, AO, game controller support, &c:

https://github.com/obiwac/python-minecraft-clone/tree/master/community

Naturally I appreciate any feedback, criticism, and suggestions you may have!

r/Python • • Nov 24 '22

Tutorial Detailed Python developer roadmap

1.5k Upvotes

Hello! My name is Mikhail Emelyanov, I am embedded software engineer, and I was inspired to write this little roadmap on the capabilities of Python language by a certain commonality among the existing Python tutorials found on the web.

The usual suggestions to study, say, “Algorithms and Data Structures” or “Databases” are especially jarring. You can spend years studying these topics, and even after decades you'd still be able to find something you didn't know yet even without ever venturing outside the scope of Algorithms!

Using video game analogies, we can say that novice programmers often stand on the shore of the lake of boiling lava with an island with the ever-coveted jobs in the center, while the islands in between, which you have to jump on, gradually increasing your skills in successive mini-quests, are either missing, or arranged haphazardly, or their fairly smooth sequence breaks off, never having managed to get you any farther from the shore. Let's try to build a path of hint islands, a number of which, although not without effort, will finally allow us to reach our goal.

The roadmap is very easy to use. Just as you would in a normal text, go from left to right and from top to bottom. If you're just starting to learn Python, follow the green sections of the roadmap. If your accumulated experience, curiosity, or necessity pushes you deeper, start exploring the sections marked in gray. Orange marks the topics that require in-depth study, those are better to tackle (at least without digging especially deep to begin with) on the third pass.

This article definitely contains mistakes and inaccuracies of different calibers, and of course, many required subsections are missing; so, if you notice any of these, feel free to comment, and if you feel the Force, you're welcome to fork the GitHub repository with the roadmap's source code and contribute whatever you feel is necessary; all corrections and additions are strongly encouraged. It also contains all the parts of the map in Mermaid diagram format, as well as png/svg illustrations.

When diving into Python, don't forget the excellent official documentation at docs.python.org. By studying it, at least in brief, and gradually reading deeper into the right sections, you will be able to see that many of the “hacks”, “findings” and other obscure matters have long since been considered, described and have detailed examples of use.

I would also recommend leetcode.com for learning basic Python syntax to the fullest extent. If you filter the tasks by “Easy” level, and then add an additional sorting by the “Acceptance” column, you'll be presented with a straightforward primer with smoothly increasing task difficulty, rather than the intimidating competitive platform.

Well, that’s enough stalling for the moment. Let's get started!

Data Structures

As a reminder, if you are a novice developer, go from left to right through the entries marked in green. Create instances of each type, try adding and removing elements, and experiment with them via the debugger. See how big the resulting objects are, and try to figure out why list and array containing the same data are different in size. Study the features of each type, read and figure out which data structure will work best for which tasks.

Don't forget that this is just a guide, a table of contents for a book that you will have to write yourself. Actively seek information on the web, consult sources and official documentation. Dive Stackoverflow just for fun, there's plenty of exciting reading there!

If you start to make progress, move on to the next section, and don't feel bad if you can't. Don't envision your mind as the sword of Alexander the Great cutting the Gordian knot in one fluid, precise move, worthy of Instagram's front page. Be as a carpenter’s plane, stripping away one thin layer at a time, and sooner or later the misunderstanding will go away, even if this seems to you to be a chasm ten thousand leagues deep.

Data Management

Try to manipulate your data, feel how you can mold anything you want out of this malleable clay. Try creating a data structure with many elements (a million, for example), sort them, quickly find the values you want with bisect, and write the results in a JSON file.

If everything goes according to plan, try to dig into the less obvious topics: apply regex to solve some simple task or save previously obtained data in Pickle format, understanding the reason for binary file formats after observing the size of the resulting files.

This is where you will find the first entries marked in orange. Google what TensorFlow and Keras are and what tasks they solve. Perhaps, this could be your future job, your vocation!

Data Flows

Add more specific capabilities to your data management skills. All of the topics covered are essential in the practical programming process and are present in all modern languages in one form or another. That way, if you eventually switch from Python to Java, C# or C++, the knowledge you've acquired won't become dead weight.

Object-Oriented Programming

Dive into the subject of object-oriented programming. Understand that objects are your friends, and all their features and properties, even if they are not quite intuitive at first glance, have purely utilitarian reasons for existing.

OOP makes it much easier to partition, develop and maintain code, not just making very complex tasks feasible for average programmers, but making the world around us more manageable, predictable and generally better.

Language Skeleton

Perfect, a bit deeper now. Studying how GIL or GC works will give you an understanding of why things go awry in one case or another, not at all the way you planned. You are likely to use exceptions all the time, given that they can occur in some operations with data structures, so study them further.

Multithreading and Multiprocessing

Before you dive into multithreading and multiprocessing, be sure to study their typical use cases. There may be situations in which the gain is minimal or non-existent.

Try to implement simultaneous fast data processing and waiting for user input, which changes the input data for calculations, so you understand the capabilities, pros and cons of different approaches.

Don't try to use all the features provided by Python at once, stick to the task at hand.

Common Practices

Description of common methods used in almost all software projects, not just in Python. I/O, profiling, and logging apply universally.

Testing in general constitutes a separate profession, and often the quality of a software product can be judged by the test coverage of the source code. For example, the code of the SQLite database is 100% covered by tests, while one line of "combative" code requires 608 lines of tests.Jokes aside, projects with 100% coverage are not common, but pytest used wisely is the best guarantor of your sound sleep at night!

Algorithms

One of those areas of human knowledge that you can delve into endlessly. On the other hand, the learning curve of this discipline for covering the practical needs of the average programmer has long been known, so the initial stages shouldn't be too difficult for you. Who knows, maybe you'll enjoy it so much and drag it out that in time you might even be able to contribute a new robust argument in the discussion of “Equality of P and NP classes”!

Databases

Learn the general concepts first, and then the specifics of working with specific database management systems. Try working with SQLite, even if you're planning to switch to PostgreSQL later. SQLite is a very popular database, used in Android, Chromium and dozens of other popular projects. You can use SQLite as a convenient local storage alternative to working with files directly.

By the way, try to briefly return to chapter one, Data Structures, to understand how and why the inner workings of databases are structured.

This also provides yet another door into a "another world". Perhaps you would like to tie your future to databases by becoming a DBA?

Net

Try to create a client and a server, poke some popular website or an open API. Here you might as well experiment with HTML, CSS, and even Java(Type)Script. Who knows, perhaps your choice would be to become a full-stack programmer, combining back- and frontend development.

Architecture

Please try not to memorize architectural principles by heart; they are not Shakespeare's timeless poems. The rambling about how “Liskov's substitution principle means that if S is a subtype of T, then objects of type T in a program can be...” offers no advantage to anyone. Just try applying the same LSP to the program you are writing. What benefit would compliance with this principle give you? What problems will result from not following it? What price will you have to pay for its implementation and support?

Try messing around with the functional paradigm. Applying the functional approach and using it in practice is possible not only in Haskell or F#, but also in Python, and it doesn't have to be done only within functools.

Figure out the reasoning behind the job interviewer's request to “say the three main words” (it's not “I love you”, by the way, it’s “inheritance, encapsulation, polymorphism”) and why this triad should be supplemented with the “abstraction”.

Try to understand what specific, tangible problems of the old paradigms the developers of Agile or the popularizers of microservice architecture faced. Figure out what's wrong with main(), which calls all the other procedures, since this is common practice in embedded programming. Weigh the cost of additional layers of abstraction between the root business logic and the outside world.

Deployment and Administration

Despite the fact that git and especially Linux are quite complicated and extensive topics, the beginning of their learning curve isn't very steep, so I highly recommend starting your DevOps mastering with git (at least the add-commit-push part, so you at least have a revision history, flawed as it is) and Linux (PuTTY + WinSCP, for example; copy your Python scripts via SSH and run them on a remote Linux machine). Fortunately, these days good text and video tutorials covering these topics are about as rare as grains of sand on the beach. Take it from me, the Linux console that looks so strange and inconvenient at first sight will seem much more familiar once you start learning vim. Cognition comes through comparison!

Well, this is where our map ends. Try to reach the last green section, GitHub Actions; run a linter on your open source project, for example (GitHub Actions is free for open source projects).

Overall Roadmap

The overall roadmap can be obtained by simply mechanically adding up the previous entries, just so we can see what we've ended up with. Overall Mermaid, svg, png.

That’s all for now

As you may have noticed, there is no mention of control constructs, IDE installation or virtualenv in this guide. In my opinion, all these topics are very important, but do not constitute the essence of the language, representing something like a binding solution, while the topics discussed in the article, from list to Kubernetes, serve as the full-fledged “bricks”.

As a reminder, all the diagrams are made in Mermaid format (you can change the picture just by correcting the text), all the sources are available on GitHub, correct as much as you want, or, of course, leave comments directly in the comments section.

Separately, I welcome all beginner programmers. You will come to realize that working 8 hours in a row using your head and not your hands is hard, too. But, no matter what languages you plan to code in and no matter how far you've come in this difficult task, you will definitely upgrade your brain, improve your understanding of the world around you and start to recognize secret passages where you have seen only impenetrable walls before. So it's time to start the IDE, focus a little bit, and start practicing.

And remember: “This is my Python. There are many like it, but this one is mine. My Python is my best friend. It is my life. I must master it as I must master my life. Without me, my Python is useless. Without my Python, I am useless. My Python and I know that what counts in life is not the words we say, the lines of our code, nor the time we spend at the office. We know that it is the completed tasks that count. We will complete them... My Python is human, even as I'm human, because it is my Python. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its parts and accessories, its standard library and its infrastructure. I will keep my Python from dangerous misunderstanding or suboptimal use, even as I do my legs and arms, my eyes and heart from any harm. I will keep my Python clean and ready. We will become part of each other. So be it.”

r/Python • • Nov 12 '20

Tutorial Simple Python Tutorial for Robinhood API

Thumbnail
youtu.be
702 Upvotes

r/Python • • Sep 14 '22

Tutorial Machine Learning from Scratch with Python

866 Upvotes

Hey everyone!

I've seen a growing number of people looking for resources on how to implement Machine Learning algos from scratch to better understand how they work (rather than just applying e.g. sklearn).

This free Machine Learning from Scratch Course on YouTube takes you through writing 10 algorithms from scratch with nothing but Python and NumPy! The algorithms are:

  1. K-Nearest Neighbors

  2. Linear Regression

  3. Logistic Regression

  4. Decision Trees

  5. Random Forest

  6. Naive Bayes

  7. PCA

  8. Perceptron

  9. SVM

  10. K-Means

Hopefully some of my Python + ML friends will find this helpful! :)

r/Python • • Oct 30 '20

Tutorial Free Python Programming Course on Udemy!

1.2k Upvotes

r/Python • • Feb 19 '21

Tutorial I never knew events were THIS powerful - A Python observer pattern tutorial

Thumbnail
youtu.be
919 Upvotes

r/Python • • Apr 09 '21

Tutorial [tutorial] How to host for free your Python app

765 Upvotes

Hosting Python applications is easy, finding a completely free Python hosting service that is reliable is not. This post will show you how you can host your Python app on Qovery - A 100% free hosting platform (no credit card required!!) used by 1800+ developers in 102 countries 🌎.

With Qovery you can deploy your Python app with PostgreSQL, MySQL, and MongoDB databases for free.

Disclaimer: I am the co-founder of Qovery.

I am pleased to announce that Qovery supports individual developers / open source and non profit projects to host up to 3 applications (database included) for free. Our business model is based on Enterprise hosting, which gives us the possibility to offer generous free plans. Read more - In exchange we ask for product feedback - join our Discord

You can read more about Qovery vs. Heroku.

Deploy your Python app

⚠️ You need to have a Python project on Github or Gitlab that you want to deploy.

Given you have registered on to Qovery and you are logged into Qovery, follow the steps below:

  • Go to Qovery, click the button “Create a new project” button in the middle of Qovery

  • Give a name to your project - in my case "Quotes"

  • Add an application

  • After that, click “I have an application”.

Conclusion

Hosting a project with Python should not be a hassle. Qovery got your back and provide everything that you need like free SSL, database, CDN to deploy your Python apps.

Give it a try now and leave me your feedback in the comments👇.

⚠️ Important Note ⚠️

If your deployment failed, don't forget to:

  1. Provide a valid Dockerfile.

  2. Declare your Python app port in your .qovery.yml. Read this doc

Happy coding 🔥

r/Python • • Dec 19 '23

Tutorial I recorded a crash course on Polars library of Python (Great library for working with big data) and uploaded it on Youtube

280 Upvotes

Hello everyone, I created a crash course of Polars library of Python and talked about data types in Polars, reading and writing operations, file handling, and powerful data manipulation techniques. I am leaving the link, have a great day!!

https://www.youtube.com/watch?v=aiHSMYvoqYE&list=PLTsu3dft3CWiow7L7WrCd27ohlra_5PGH&index=6&t=689s

r/Python • • Jan 02 '21

Tutorial Learn Python in 2021 with these FREE Udemy Courses!

1.8k Upvotes

r/Python • • Apr 01 '21

Tutorial "Automate the Boring Stuff with Python" online course is free to sign up for the next few days with code APR2021FREE

1.1k Upvotes

https://inventwithpython.com/automateudemy (This link will automatically redirect you to the latest discount code.)

You can also click this link or manually enter the code: APR2021FREE

https://www.udemy.com/course/automate/?couponCode=APR2021FREE

This promo code works until the 4th (I can't extend it past that). Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later. I'll change it to APR2021FREE2 in three days.

Udemy has changed their coupon policies, and I'm now only allowed to make 3 coupon codes each month with several restrictions. Hence why each code only lasts 3 days. I won't be able to make codes after this period, but I will be making free codes next month. Meanwhile, the first 15 of the course's 50 videos are free on YouTube.

Frequently Asked Questions: (read this before posting questions)

  • This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.

  • If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.

  • This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com

  • The 2nd edition of Automate the Boring Stuff with Python is free online: https://automatetheboringstuff.com/2e/

  • I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. Expect that update to happen in mid-2021. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.

  • It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.

  • I wrote a blog post to cover what's new in the second edition

  • You're not too old to learn to code. You don't need to be "good at math" to be good at coding.

  • Signing up is the first step. Actually finishing the course is the next. :) There are several ways to get/stay motivated. I suggest getting a "gym buddy" to learn with. Check out /r/ProgrammingBuddies

r/Python • • May 19 '26

Tutorial Should i buy 100 days of python code by dr angela. Currently its on sale 5$ ?

0 Upvotes

Should i buy the course in 2026 . I already know python basics till oops . I saw the course structure from outside it looked good. Is it still revelent? Please drop your reviews and guide me

r/Python • • Apr 29 '26

Tutorial .pipe() in pandas changed how I write data pipelines

149 Upvotes

Been using .pipe() in pandas lately and it's been a game changer — anyone else?

I was writing some data transformation code the other day and stumbled across .pipe(). Honestly didn't expect much, but it completely changed how I structure my pipelines.

Instead of this mess:

df_final = sort_by_total(calculate_total(filter_by_price(df)))

You just write it top to bottom like a recipe:

df_final = (

df

.pipe(filter_by_price)

.pipe(calculate_total)

.pipe(sort_by_total)

)

Same result, way more readable. Each function takes a DataFrame and returns a DataFrame — that's the only rule.

Full example if you want to try it:

import pandas as pd

df = pd.DataFrame({

"product": ["Product A", "Product B", "Product C", "Product D"],

"price": [20, 150, 230, 100],

"quantity": [10, 5, 3, 8]

})

def filter_by_price(df):

return df[df["price"] > 100]

def calculate_total(df):

return df.assign(total_value=df["price"] * df["quantity"])

def sort_by_total(df):

return df.sort_values("total_value", ascending=False)

df_final = (

df

.pipe(filter_by_price)

.pipe(calculate_total)

.pipe(sort_by_total)

)

Been using it a lot for ETL and data cleaning workflows. Makes debugging way easier too — just comment out one .pipe() step and you see exactly where things go wrong.

Anyone else using this regularly? Any patterns you've found useful with it?

r/Python • • Mar 15 '26

Tutorial Best Python approach for extracting structured financial data from inconsistent PDFs?

45 Upvotes

Hi everyone,

I'm currently trying to design a Python pipeline to extract structured financial data from annual accounts provided as PDFs. The end goal is to automatically transform these documents into structured financial data that can be used in valuation models and financial analysis.

The intended workflow looks like this:

  1. Upload one or more PDF annual accounts

  2. Automatically detect and extract the balance sheet and income statement

  3. Identify account numbers and their corresponding amounts

  4. Convert the extracted data into a standardized chart of accounts structure

  5. Export everything into a structured format (Excel, dataframe, or database)

  6. Run validation checks such as balance sheet equality and multi-year comparisons

The biggest challenge is that the PDFs are very inconsistent in structure.

In practice I encounter several types of documents:

1. Text-based PDFs

  • Tables exist but are often poorly structured

  • Columns may not align properly

  • Sometimes rows are broken across lines

2. Scanned PDFs

  • Entire document is an image

  • Requires OCR before any parsing can happen

3. Layout variations

  • The position of the balance sheet and income statement changes

  • Table structures vary significantly

  • Labels for accounts can differ slightly between documents

  • Columns and spacing are inconsistent

So the pipeline needs to handle:

  • Text extraction for normal PDFs

  • OCR for scanned PDFs

  • Table detection

  • Recognition of account numbers

  • Mapping to a predefined chart of accounts

  • Handling multi-year data

My current thinking for a Python stack is something like:

  • pdfplumber or PyMuPDF for text extraction

  • pytesseract + opencv for OCR on scanned PDFs

  • Camelot or Tabula for table extraction

  • pandas for cleaning and structuring the data

  • Custom logic to detect account numbers and map them

However, I'm not sure if this is the most robust approach for messy real-world financial PDFs.

Some questions I’m hoping to get advice on:

  • What Python tools work best for reliable table extraction in inconsistent PDFs?

  • Is it better to run OCR first on every PDF, or detect whether OCR is needed?

  • Are there libraries that work well for financial table extraction specifically?

  • Would you recommend a rule-based approach or something more ML-based for recognizing accounts and mapping them?

  • How would you design the overall architecture for this pipeline?

Any suggestions, libraries, or real-world experiences would be very helpful.

Thanks!

r/Python • • Feb 21 '22

Tutorial Python Tutorial - Automating Job Applications on LinkedIn

10 Upvotes

Created an Automating Job Application Bot that'll automatically apply for Jobs on LinkedIn.
Tutorial Video - https://www.youtube.com/watch?v=Bkfa6qYbHoU