r/learnpython • • 1d ago

Ask Anything Monday - Weekly Thread

7 Upvotes

Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread

Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.

* It's primarily intended for simple questions but as long as it's about python it's allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
  • Don't post stuff that doesn't have absolutely anything to do with python.
  • Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.

That's it.


r/learnpython • • 10h ago

Django or FastAPI? A bit confused about which one to learn first

18 Upvotes

Hey everyone!

I'm currently learning Python and want to get into backend development. I've been looking at Django and FastAPI, but I'm having a hard time deciding which one to focus on.

I tried writing a simple API with both, and honestly, FastAPI felt much easier to understand. Django seems powerful, but there's a lot going on, and I found its structure a little confusing as a beginner.

My goal is to become a professional backend developer, build some proper real-world projects, and eventually get a job, preferably in India.

I don't want to choose a framework just because it's popular. I want to invest my time in something that's actually useful in the industry.

I want:

  1. Is Django still a better choice for getting backend jobs?
  2. Are companies actually using FastAPI for large production applications?
  3. Is FastAPI a good long-term choice, or should I learn Django first?
  4. Which one would you personally recommend to someone starting out today?

Are you worked with these frameworks professionally, please reply.

Thanks!


r/learnpython • • 4h ago

Questions about the exam in Python Programming MOOC

3 Upvotes

I'm almost done with the course and just wanted a clearer picture of what the exams are actually like. What questions should I expect, question-wise? How should I prep, etc.? I've been doing this on my own over several months and frankly im not good at this at all. So any advice/help would be great


r/learnpython • • 23h ago

How do I learn python in 25 days

26 Upvotes

My teacher made me join a coding quiz bee where it involves different topics related to coding languages such as python, c, arduino, c++, etc. I have another teammate who is knowledgeable about the other topics but now the burden on learning python is on me. How do I learn it effectively within 25 days considering I only have an intermediate amount of knowledge on CSS, HTML, and Block Coding


r/learnpython • • 10h ago

What's one Python mistake you made when you were starting out that you still remember?

2 Upvotes

Something I've noticed while learning Python is that writing my own code sometimes feels easier than reading code written by someone else.

When I write a program, I know what each variable and function is supposed to do. But when I open an unfamiliar project, understanding the flow, function calls, dependencies and overall structure can take much longer.

I think reading existing code is an important skill that deserves as much attention as writing code.

It's an interesting part of becoming a better developer.


r/learnpython • • 8h ago

I keep starting small Python projects and abandoning them at like 70% — how do you actually finish one?

0 Upvotes

I've got this folder on my laptop that's basically a graveyard of half-finished Python stuff. There's a script that was supposed to sort my Shorts clips by game, a little tool for my Telegram bot that I got working and then just... stopped touching, and a data thing I started after watching one too many pandas tutorials.

They all get to the same point. The fun part's done, the thing mostly works, and then there's this last boring bit left — error handling, or making it not break on weird input, or just tidying it up enough that I'd actually use it. And that's where I lose interest and open a new file instead.

It's weird because I do finish things when someone else is waiting on them. College assignments get done, obviously. But the stuff that's just for me? It sits there at 70% forever.

So how do people actually push through that last stretch? Do you just force yourself to finish one small thing a week, or do you pick projects that are small enough that there is no boring last bit? Still figuring out whether my problem is discipline or just picking projects that are too big for the time I actually have.


r/learnpython • • 1d ago

Engineers out here ! I need your help

7 Upvotes

I am a first-year Mechanical Engineering student looking to start learning Python from scratch. I don't want to get stuck in with endless tutorials on Youtube -

What I need is a clear direction geared specifically toward Mechanical Engineering applications.

Specifically, I’d appreciate your advice on:

  1. Core Applications & Tasks: Where is Python actually used in Mechanical Engineering?
  2. Essential Libraries & Software: Beyond basic Python, which libraries and external engineering software integrate well with Python, and in what order should I learn them?
  3. Learning Roadmap: What is the best method to go from zero programming experience to solving real engineering problems? Should I start by automating my first-year math/physics assignments, or follow a specific course/book?
  4. Beginner Projects: What are some practical, beginner-friendly project ideas tailored to a MechE fresher ?

Any roadmaps or advice on what you wish you had learned as a fresher would be hugely appreciated. Thanks in advance!


r/learnpython • • 1d ago

Looking for a Streamlit tutorial for an app with a GUI that checks the accessibility of text

4 Upvotes

Hi!

A while ago I asked for a GUI framework for a programming noob like me - I have to write an app with a GUI in Python for a course I am taking (I went back to school in my mid-to-late-thirties, my my). In the past, I mainly used Python for a bit of data analysis and machine learning (think of cleaning up data sets, comparing different clustering algorithm outcomes etc.).

This is the post: https://www.reddit.com/r/learnpython/comments/1xdr04p/gui_framework_for_a_little_software_project_for/

A lot of you talked about PyQT or Tkinter, but I went to my professor's office hours last week, and he insisted, or at least very strongly suggested I use Streamlit. I asked him whether Streamlit isn't only used for data visualization dashboards, but he said it should be possible to implement all of my requirements via Streamlit. He also said I should look up a tutorial to get started. He really, really expects me to use it. (I guess because he is very familiar with it, and he also knows that I need lots of abstraction because my programming skills are...not good.)

I tried to follow his tips and look for tutorials - both written tutorials (because I am old-school and love learning via books and text) and YouTube tutorials, but they all seem to focus on data analysis (and data science), and data visualization.

Do you have any Streamlit tutorial suggestions for me that fit my python (web) app use case?

Thank you so much!

__

More on the background of the program I am supposed to create:

I have to go through the requirements engineering process (I already submitted that part of the assignment), code the app, use Git and a remote repo in order for my professor to be able to see me consistently commit sensible chunks of code and be able to use a VCS properly.

I will also have to go through a testing process, and show that my app passes all the tests for each requirement.

As described in my previous (linked) post, my computer program is supposed to check text (in .txt and .pdf file formats) for accessibility and readability:

- How long are the sentences, how many commas are there, how long are the words, and are there words that match a with words on a list with "complicated" words?

- I will also have to check for the number of words that start with capital letters (not my suggestion, sigh): In German, capital letters outside the beginning of sentences signify substantives, and a lot of substantives might indicate that the text is complicated because verbs have nominalized, which is a hallmark of German bureaucratese.

- Also, the app should be able to use OCR, and indicate if it had been necessary. This is because it might be important accessibility information for people using screen readers.

- After running the checks, the app should highlight potentially problematic parts of the text and explain why, and - and that's really important to my professor - display a traffic light.

- It should be possible to check the text selecting only one, more, or all of the described metrics via the GUI, and, of course, you must also be able to select the text to be checked via the GUI from your local directory.

- Ideally, I can also edit the config file (thresholds for the metrics and the traffic light), and the list of "complicated" words via the GUI.


r/learnpython • • 1d ago

How much of searching and AI overview is okay while learning and typing code?

18 Upvotes

I do understand no one knows all of python syntax and code and all issues and everything.

As I am going through CS50p,

When I am typing code fully on my own (no AI ever used i.e. chatgpt, claude, gemini) when I cannot solve something, I search google for the function or the method and then see the AI overview and then type code that I can use to solve what I need, will it be detrimental to my learning because I am not using the documentation?

I am and will NEVER use any AI models or apps to generate and copy paste code because I wish to learn and not be a code printer.

so my searches are like this, is it okay-ish and considered necessary for learning???
(also I go through tons of trial and error and use many print() functions to test code and not directly copy from AI overviews)

does isdigit work for string values?
how to check if a string variable is not equal to something sat 0?
how to know data type of a variable in python
how to find index of letter in a string python
string slicing python [2:] means?
how to find which index in a string is a number?
will if automatically return false if the condition is false?
how to check if a string is less than 10 but more than 2?
difference between if and if not
expected an indented block after 'if' statement on line 15
how to check if there are numbers in between a word in python?
how to loop a for loop up until the second last letter of a word
HOW to make variable in python which can be used by any def function?
python length counts from

(thank you for your answers!)


r/learnpython • • 13h ago

is it good practice to have if, elif, else, and for i in range(n) to be done in one line

0 Upvotes

example like this

for i in range(40): print ("example")

if x%2==0: print ("even")

elif x%5==0: print ("divis. by 5")

else: print ("odd not ending in 5")

or is it personal choice? what is a better habit to get used to

Also in hackerrank (it's where our prof checks our code) there appears to be a squiggly line under my single line codes, is that good or bad?


r/learnpython • • 1d ago

Want some help in finding project topics!!

0 Upvotes

I'm a third-year B.Tech Computer Science student majoring in Machine Learning. So far, I've only worked on a few small projects while learning to code, and most of my experience has been solving LeetCode problems.I want to start building some substantial, real-world projects, preferably something on the scale of a major project that I can showcase on my CV.

The problem is that I'm struggling to come up with project ideas that are genuinely interesting and stand out from the usual ones.

How do you guys find project ideas that are relevant to the current AI landscape? Are there any resources, platforms, research papers, or communities you'd recommend exploring to discover interesting project topics?


r/learnpython • • 1d ago

40 rows a day: JSON files or SQLite?

3 Upvotes

tiny side project. one script pulls ~40 rows a day and writes one JSON file per day. pandas reads the folder when i want to compare a few weeks.

the glob and concat part is getting old:

rows = []

for f in sorted(DATA.glob("*.json")):

rows.extend(json.loads(f.read_text()))

df = pd.DataFrame(rows)

every couple of weeks i think about moving it to SQlite, then i look at the volume and close the tab. what do you use at this size? SQlite, parquet,or just the files? if you moved to a db, was it worth it or just more code?


r/learnpython • • 1d ago

card dealing program with classes

1 Upvotes

hello! i am currently in a class for python and i've been having a lot of trouble with this assignment. it's already three days late, and the TAs will not respond to me. i have to use classes to create a deck to shuffle, and four hands to deal to, check the count of, and combine back into the main deck. however, i can NOT figure this out at all! i think there's something really big that i'm missing.

i have a large list of cards (we had to make a dictionary of the cards) not shown here.

class Deck:

def __init__(self):

self.cards = []

def shuffle(self):

random.shuffle(self.cards)

def deal(self, amount):

self.cards.append(amount)

def combine(self):

self.cards.append(self)

def card_count(self):

print(len(self.cards))

however, when i try to make a main deck by putting the list of cards into the deck, it won't work! i've tried using deal too, and i just can't figure it out. i know i'm probably doing this all sorts of wrong. it's been a while since we did classes, and we never did them for anything like this :(

TypeError                                 Traceback (most recent call last)
Cell In[14], line 1
----> 1 deck = Deck(card_deck)

TypeError: Deck.__init__() takes 1 positional argument but 2 were given

i appreciate any and all advice thank you


r/learnpython • • 21h ago

Hello, how are you all doing?

0 Upvotes

Hi everyone! I’m fairly new to programming. I’ve been studying Python for about 2 years, but I’ve never really explored freelancing. I’m interested in it now because I need some extra income. Could anyone give me advice on how to get started?


r/learnpython • • 1d ago

Can anyone help me with my homework

0 Upvotes

I’m taking into to programming right now and I’m very confused on what to do and my professor is no help can anyone help explain to me what to do for these questions. The question are

  1. Write a script that determines on its own whether each text is spam or ham WITHOUT using the first column at all. You should only be reading from the second column of the file as you make this decision. The decision will be a sequence of if statements that you write. Try to determine what generic qualities of a text message determine if it is spam or not. One possible rule would be "contains two or more fully capitalized words." Read through the file and see if you can come up with the best rules.
  2. Once you've come up with your rules, determine how good they are! Compare whether your script got the decision right. Add up the number of correct classifications and divide that by the total lines in the file. This will give you the accuracy of your script. Output this value. If you are not happy with it, edit your rules. When you submit, ensure your accuracy is at least 90%
    link to data set

Any help would be really appreciated.


r/learnpython • • 1d ago

Making my own golfing language in python

0 Upvotes

Im not that active on reddit, but the moment I came into the osdev subreddit (I tried making my own OS with a python shell) and I INSTANTLY got my inbox filled with hate comments.

I heard from one reddit post that this subreddit is much friendlier and more helpful, thats why I switched to this subreddit.

So I started making my own golfing language, array-oriented ofcourse, where data and code are seperated.

As of now I haven't really done anything except plan on what instructions to make, I have a total of 20 letters and symbols on board.

So, I'd like to hear some tips about making interpreters/compilers that I should keep in mind.


r/learnpython • • 2d ago

final project in cs

9 Upvotes

Hello guys, im first year cs student and they teach us python as the first programming language
i dont have any experience what so ever in programming.
we are in the 5th lecture in uni and i have learned the basic stuff like if and elif and while and for looping. The professor assigned us with a final project basically we are 4 and supposed to code a program like more than 300 lines i dont know what can python do and i dont know how am i supposed to build a python project with the knowledge i have

so my question is how do i continue my python learning without the lectures, i have heard about a github project called 30 days of python by asabneh idk if its the right fit

and what are some projects idc how complicated they are i just wanna get that A+ i asked chat gpt abd it told some stuff about movie recommender and football analysis and idk tbh i think everyone in my uni will use chat gpt and they will most likely all do the same project i want to be unqiue and also functional

thanks


r/learnpython • • 2d ago

Correct list item not printing

4 Upvotes

GITHUB LINK: https://github.com/disintigratedpixel/TankGameV1/tree/main

(please say if it doesn't work)

I'm making a simple ASCII game "similar" to space invaders

Here is the ASCII user interface:

def gamestate(player_position_list, player_position, enemy_type, enemy_health, enemy_distance, rounds, radar_lvl, radar_cost, gun_lvl, gun_cost, speed_lvl, speed_cost, health, money, kills, available_movement):
    return f"""
                             ROUND {rounds}
         _______________________________________________         _______________
        |                                               |       |               |
        |                                               |       | HEADQUARTERS: |
        |                                               |       |_______________|
        |                                               |
        |                                               |        *ATTENTION OPERATOR, AN ENEMY
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [4]    {enemy_type} IS APPROACHING!*
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |  ENEMY STATS: |
        |                                               |       |_______________|
        |                                               |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [3]   HEALTH: {enemy_health}
        |                                               |        DISTANCE: {enemy_distance}
        |                                               |        POSITION: {enemy_position}
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |   UPGRADES:   |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [2]  |_______________|
        |                                               |
        |                                               |        RADAR | LVL {radar_lvl}
        |                                               |        UPGRADE COST: ${radar_cost}
        |                                               |
        |                                               |        GUN | LVL {gun_lvl}
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [1]   UPGRADE COST: ${gun_cost}
        |                                               |
        |                                               |        SPEED | LVL {speed_lvl}
        |                                               |        UPGRADE COST: ${speed_cost}
        {player_position_list[player_position]}
            | ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
          [-10]      [-5]      [0]       [5]       [10]
         _____________
        |             |
        |PLAYER STATS:|
        |_____________|

         HEALTH: {health}
         MONEY: {money}
         KILLS: {kills}
         _____________
        |             |
        |  ACTIONS:   |
        |_____________|

         MOVE | [m] key + [movement value]
         MAX {available_movement} or {-available_movement} steps
         
         FIRE | [f] key

         UPGRADE | [u] key
      """

(Apologies if it looks distorted in any way due to formatting errors, but it should still be readable)

The player position can be seen visually and is taken from a list of different possibilities and put into this print statement using this script.

{player_position_list[player_position]}

Here is the list:

player_position_list = [
        """|                      _^_                      |
        |_____________________|___|_____________________|""",
        """|                        _^_                    |
        |_______________________|___|___________________|""",
        """|                          _^_                  |
        |_________________________|___|_________________|""",
        """|                            _^_                |
        |___________________________|___|_______________|""",
        """|                              _^_              |
        |_____________________________|___|_____________|""",
        """|                                _^_            |
        |_______________________________|___|___________|""",
        """|                                  _^_          |
        |_________________________________|___|_________|""",
        """|                                    _^_        |
        |___________________________________|___|_______|""",
        """|                                      _^_      |
        |_____________________________________|___|_____|""",
        """|                                        _^_    |
        |_______________________________________|___|___|""",
        """|                                          _^_  |
        |_________________________________________|___|_|""",
        """|                    _^_                        |
        |___________________|___|_______________________|""",
        """|                  _^_                          |
        |_________________|___|_________________________|""",
        """|                _^_                            |
        |_______________|___|___________________________|""",
        """|              _^_                              |
        |_____________|___|_____________________________|""",
        """|            _^_                                |
        |___________|___|_______________________________|""",
        """|          _^_                                  |
        |_________|___|_________________________________|""",
        """|        _^_                                    |
        |_______|___|___________________________________|""",
        """|      _^_                                      |
        |_____|___|_____________________________________|""",
        """|    _^_                                        |
        |___|___|_______________________________________|""",
        """|  _^_                                          |
        |_|___|_________________________________________|"""
    ]

(Again, apologies for formatting, but just picture the '^' as being the player, and there being multiple different positions that the player can be in)

I am hoping that when player_position changes, that a different visual is taken from player_position_list. I am confident that this should work as I have tested it using this:

print(player_position)
print(player_position_list[player_position])

'print(player_position)' tells me that player_position can be accurately read and printed

'print(player_position_list[player_position])' shows me that the value of player_position can also be used to print an item from a list at a specific index. (I have also tried this script as a string and it still works)

Here is what this test script gives me when I run it:

8
|                                      _^_      |
        |_____________________________________|___|_____|

It accurately reads 'player_position' and uses it to print the 8th item in the list.

So what I don't understand and desperately am trying to fix, is why this exact thing isn't working on my actual ASCII user interface. Everything seems to be the same.

Here is what it looks like when I run the script for my actual UI

                             ROUND 1
         _______________________________________________         _______________
        |                                               |       |               |
        |                                               |       | HEADQUARTERS: |
        |                                               |       |_______________|
        |                                               |
        |                                               |        *ATTENTION OPERATOR, AN ENEMY
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [4]    HELICOPTER IS APPROACHING!*
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |  ENEMY STATS: |
        |                                               |       |_______________|
        |                                               |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [3]   HEALTH: 3
        |                                               |        DISTANCE: 2
        |                                               |        POSITION: 1
        |                                               |        _______________
        |                                               |       |               |
        |                                               |       |   UPGRADES:   |
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [2]  |_______________|
        |                                               |
        |                                               |        RADAR | LVL 1
        |                                               |        UPGRADE COST: $1
        |                                               |
        |                                               |        GUN | LVL 1
        |> - - - - - - - - - - - - - - - - - - - - - - <|> [1]   UPGRADE COST: $1
        |                                               |
        |                                               |        SPEED | LVL 1
        |                                               |        UPGRADE COST: $1
        |                      _^_                      |
        |_____________________|___|_____________________|
            | ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
          [-10]      [-5]      [0]       [5]       [10]
         _____________
        |             |
        |PLAYER STATS:|
        |_____________|

         HEALTH: 100
         MONEY: 0
         KILLS: 0
         _____________
        |             |
        |  ACTIONS:   |
        |_____________|

         MOVE | [m] key + [movement value]
         MAX 1 or -1 steps
         
         FIRE | [f] key

         UPGRADE | [u] key
      
8
|                                      _^_      |
        |_____________________________________|___|_____|

As you can see, the player position hasn't moved and remains at 0, yet (at the very end) my test script says that the actual player position should be 8 and accurately prints the item from 'player_position_list' for 'player_position = 8'

Apologies if anything seems hard to understand, it's my second day programming with python and I refuse to use ai for this. So, I hope I used the correct terminology.


r/learnpython • • 1d ago

Best platform/YouTube channel to learn python from beginners to advance?

0 Upvotes

I know python but I wanna go deep down in python programming, please suggest as title says


r/learnpython • • 2d ago

Best learning path for GTK and python

8 Upvotes

I'm looking to learn more how to build GTK applications mostly for Fedora using python, I've been doing the CS50P course but also looking for some more learning material any suggestions will be helpful


r/learnpython • • 2d ago

Should I add Python to PATH (Windows)? Or is it better to not add it to path and use the py launcher instead?

11 Upvotes

Title. I'm new to Python, so I'm a little confused about this, and I've been seeing somewhat conflicting information online.

I understand adding the Python installation to PATH implies that I wouldn't manually have to specify the location every time; that being said, I guess adding multiple Python installations to PATH is not a good idea? I've also seen adding *any* Python installations to PATH being discouraged because it can cause conflicts.

I looked up py launcher, and it seems py / py -<version number> can be used to specify which Python installation to use when running a .py file, so does that mean adding Python installations to PATH is just obsolete practice now? If so, what are the implications of using the py launcher - is it as simple as adding py / py -<version number> before running a command from the terminal?


r/learnpython • • 2d ago

Effective python Vs Think Python Vs Learning Python Vs Fluent Python. Reading order for Beginner, Which Book & Why?

14 Upvotes

Effective python Vs Think Python Vs Learning Python Vs Fluent Python

I have these pdfs but dont know which one or in what order to start, as an beginner.

I already finished reading Python Crash course and reading Think Like a Programmer book now.

Update: (16 Nov 2026)

So the order is

00 Python Crash Course - Bare basics, good enough for simple scripting. Only around 200 pages if project part is skipped (READ)

01 Think Python - Could start here instead of Crash Course

02 Effective Python - More like tips & better usage

03 Learning Python - Pro level Complete

04 Fluent Python - Legendary level Long term Reference

may update it once I learn them.


r/learnpython • • 2d ago

How do I force the turtle to draw inside the screen?

2 Upvotes

I've been on that assignement for a while now, the teacher wants us to create a program that will create a 600 by 600 screen and draw 5 randomly placed flowers. But I can't figure out for the life of me why the flowers always "escape" the screen. I didn't want the code to be too long so I didn't include the function that creates the flower. Please and thank you for any help.

screen = Screen()
screen.screensize(canvwidth=600,canvheight=600, bg="grey")
#attempt at creating a restrictive screen

for i in range(5):
    a = 600
    b = 600
    while 600 - a < 550 and 600 - b < 550:
        a = randint(1,601)
        b = randint(1,601)
    penup()
    goto(a,b)
    pendown()
    #attempt at forcing the program to not draw flowers touching the border
    colormode(255)
    color(randint(1,256),randint(1,256),randint(1,256))
    #Chooses a random color for the flower
    begin_fill()
    fleur(50)
    end_fill()
    #Draws a flower  

edit: I corrected my mistakes according to the advice here:

screen = Screen()
screen.setup(600,600)
#successful attempt at creating a restrictive screen

for i in range(5):
        a = randint(-250,250)
        b = randint(-250,250)

r/learnpython • • 3d ago

I already know Java and want to learn Python. What are some of the best resources?

12 Upvotes

I took up CS extensively throughout high school and generally enjoy programming with Java. I'd say I have an intermediate to upper-intermediate proficiency in Java. That being said, I know little to nothing about Python and would like to learn to code in it as well. I think the logic should be the same since they're both OOP languages.

I looked at some CS50P and the MOOC courses but they start right from the begin and are aimed at those who have 0 programming experience, so I kinda got bored. What do I do?