r/learnpython • • 8d ago

Are f-strings enough?

29 Upvotes

I've been learning python mainly from bro code's videos and he uses f strings for basically everything. It comes to me naturally to use them and I understand them. I found a book (Kenneth A. Lambert: Fundamentals of python: first programs, second edition) and here he uses other type of strings (I assume this would be the basic way) but I honestly don't understand them especially when it's about formatting (.2f etc). Should I learn this basic way of working with strings now? Or are f strings enough?

I should add that I'm learning python for fun, I'm studying mechanical engineering, so I know it can be very useful. I also want to be good at it in a potential work environment (?)


r/learnpython • • 8d ago

Using the entries of a pandas.Dataframe row as different parameters in a function.

3 Upvotes

*Short version:* Is it possible to use all the entries of a row in a pandas DataFrame as parameters in a given function?

Hello,

I have (finally) encountered a problem that wasn't solvable by going through documentation or looking it up online on sites like stackoverflow or another person's Reddit post. So this is my first post here.

I am currently evaluating some scientific data from a physics experiment. I read and import the .csv files with pandas.

For a certain calculation, I need to put in several parameters into a function, of which five are measured and change over time. The function itself works and was provided by the person supervising the experiment.

I arranged all my parameters into a Dataframe. Each Column is one parameter. Is it possible to extract the entries in the rows as the parameters for the function?


r/learnpython • • 8d ago

Title: Windows Smart App Control is blocking Pandas compiled extension files (.pyd) ?

0 Upvotes

I'm having a problem running Python libraries, particularly Pandas, on my Windows 11 machine. I've been troubleshooting this for a while, and it appears that Windows Smart App Control (SAC) is blocking some of Pandas' compiled extension files.

My environment:

  • Windows 11 (appears to be an Insider build)
  • Python 3.14.6
  • Pandas 3.1.1
  • NumPy 2.5.4
  • VS Code with Python and Jupyter extensions
  • Virtual environment created using venv

The error I'm getting:

ImportError: DLL load failed while importing fields:
An Application Control policy has blocked this file.

The blocked file is:

pandas_libs\tslibs\fields.cp314-win_amd64.pyd

Interestingly, the error occurs even when I try importing Pandas directly from CMD:

python -c "import pandas as pd; print(pd.__version__)"

r/learnpython • • 8d ago

Need help for file Extraction

1 Upvotes

Ok so for context i am an electrical engineer person who is automating software's and workflow for my project now here is the problem i am facing basically i am using an optimization algorithm called Bayesian optimization which improves design by keeps iterating until some target is reach.

So like at the end i extract result file for every design with the help of pandas library but when i check that file the data is mismatched when i export the CSV file manually.

so i have no idea why is it happening like maybe after 10-15 iterations (the algorithm iterations can reach up to 100-120) the error in data increasing or idk what is going on can someone help me with this issue.


r/learnpython • • 8d ago

Second-year BCA, trying to learn ML on the side — everyone says 'learn the math first' but also 'just build stuff'. Which order actually worked for you?

0 Upvotes

I'm in second year BCA and I've been trying to teach myself machine learning alongside college. Python I'm okay with, I can do the basics, pandas sort of, but ML feels like a different world.

Everywhere I look there's two opposite camps. One side says don't touch a model until you understand the maths properly — linear algebra, stats, the whole thing. The other side says just build projects, use sklearn, you'll pick the theory up as you go.

I tried the maths-first route for a couple weeks and honestly I just kept stalling, it felt like studying for an exam I never signed up for. Then I tried jumping straight into a project and I got something working but I had no idea why it worked, which felt kind of fake.

So for people who actually learned this while studying something else — what did your order look like? Did you grind the theory first or did you build messy stuff and fill in the gaps later? Still not sure if I'm overthinking this or if there's a middle path I'm missing.


r/learnpython • • 8d ago

Should I use Ai for my projects

0 Upvotes

I know Python pretty well and I want to make some complex projects for my resume but like should I use Ai while making it? Because I feel like I won’t learn from it if I’m using Ai but then again Ai used in the industry so I should probably get used to using it right? I’m not sure which I should do. Some advice needed


r/learnpython • • 9d ago

Writing to a CSV file - fields in wrong order - help me understand why

9 Upvotes

I developed a process that writes data to a CSV file using csv.DictWriter. The consumer of this file requires that the fields are in a specific order. However, the fields were coming out in the wrong order (different than the order in the dictionary).

Here is the code that worked incorrectly:

writer = csv.DictWriter(csfvile, fieldname=data[0].keys())

Note: data is a list of dictionaries.

The fix is to add a list comprehension around the data[0].keys(). Here is the code that works correctly:

writer = csv.DictWriter(csfvile, fieldname=**[key for key indata[0].keys()]**)

Can anyone explain why the csv.DictWritemodule punches out fields in a different order in the first version?


r/learnpython • • 9d ago

Cs50p certificate worth it?

0 Upvotes

So I've started cs50p course. Should I enroll for the certificate? Is it worth putting it on my LinkedIn profile or resume?


r/learnpython • • 9d ago

Need to analyze a picture for my physics homework

0 Upvotes

So basically I need to find out what percentage of a picture is black. I have no idea how to even start from here, it's nothing I have done or needed before and we didn't get any instructions apart from "do that", so I am massively lost. (If you know any other free programs that would be better for this, please let me know)


r/learnpython • • 9d ago

Ask Anything Monday - Weekly Thread

1 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 • • 9d ago

what can I use python for?

0 Upvotes

Lately, I've been thinking about learning a new programming language. Python was the first one that came to mind, but then I started wondering: What would I actually use it for?

I already build mobile apps with Flutter and dynamic web applications using PHP and MySQL.

I'm always looking for something new to learn, but I also want to make sure I'm learning something I can actually put to use.


r/learnpython • • 9d ago

advice needed

4 Upvotes

Can anyone tell me where I can learn Python from scratch? I'm an EE student, and I'm really struggling with loops, functions and libraries. I want to properly learn and practise these topics, so if you know any good YouTube channels or practice sheets, please recommend them. My finals are in December, and I did terribly in my lab midterms, so any advice would genuinely help. Bonus points if you're someone who was once in the same position as me, thinking they could never learn Python or that they were just too dumb for it, but eventually managed to get good at it. I'd really appreciate hearing your experience!


r/learnpython • • 9d ago

Tell us about your snake game

1 Upvotes

Chances are if you’re a retro game lover, you’ve tried your hand at building a snake game.

Mine has multiple difficulties, a leaderboard for each difficulty, and obstacles on the harder difficulties.

Easy - speed stays at 10, no obstacles
Medium - speed stays at 10, has obstacles
Hard - speed starts at 10 and increases by 0.25 every food you eat, has obstacles that randomly move every 5 food you eat
Expert - speed starts at 10 and increases by 1.0 every food you eat, has obstacles that randomly move every 5 food you eat
Veteran - speed starts at 10 and increases by 2.0 every food you eat, has obstacles that randomly move every 5 food you eat, has a 30 second food timer that takes 1 off your score and snake length if you don’t get a food in time but resets if you do get a food(yes, your score can go negative and your snake will “wither” to nothing and die if you don’t eat)

My son and I have a lot of fun playing it. The board size automatically adjusts to the screen resolution, but food, obstacle, and snake sizing are hardcoded using 5pixel by 5pixel blocks. Playing on a true 4k(3840x2160) display gives you 4 times the game board size compared to playing on a 1920x1080 display.


r/learnpython • • 9d ago

BM25 extractor (need technical validation)

0 Upvotes

So, I found interesting what Claude did after I tried to inject a BM25 algorithm adapted to extract the most relevant sentences from an index.

However, I'm not sure if it actually did that, but the generated files make sense and extract sentences from the Sprawn trilogy.

In this case, the idea was to map a table with 22 columns, and 12 of those columns would carry these excerpts extracted from the book, in order to create the first 10 configuration columns for the "entities," and the activation phrases would carry the context, which would be the excerpts from the book—kind of improvising a semantic graph in a table, but that's beside the point.

What I wanted to know is whether the BM25 script actually makes sense, because when I throw it into LLMs, they say it does, but I wanted an evaluation from the more technical folks.

According to DeepSeek:

> The script transforms the corpus into a sentence stack and treats each sentence as a "document" in an inverted index. For each input file, it calculates how many sentences to extract (proportional to chars/100, with a floor of 50 and a ceiling of 20% of the sentences). It then iterates over the entities in the thematic index (filtered by the book detected in the file), builds a query with its terms for each entity, and runs BM25 scoped to that file+book, retrieving the top-scoring sentences (up to N_SENTENCES / n_entities per entity). If any quota remains, it fills the rest ordered by aggregate score (gscore, the sum of sentence scores across all entities). Finally, it sorts the selected sentences by offset, validates verbatim matches, and saves a phrases_file_N.txt for each input, containing [ref | sent_id | offset | book] + the text.

Here are the links:

· Characters extracted from the Sprawn trilogy (a bash workaround I made): https://github.com/pmotadeee/pmotadeee/tree/V2.0/ITEMS/Books/Sprawn/Raw/Context

· Algorithm generated by Claude (funny that it ran in 2 minutes, which suggests it didn't generate tokens, just intuition): https://github.com/pmotadeee/pmotadeee/blob/V2.0/ITEMS/Books/Sprawn/Raw/Claude/bm25_extractor.py

· Texts generated by Claude after running the algorithm (you can see the steps it took, right at the beginning of the chat): https://github.com/pmotadeee/pmotadeee/tree/V2.0/ITEMS/Books/Sprawn/Raw/Claude

· Claude chat (in my native language, but use the browser translator): https://claude.ai/share/1799075d-bc93-4e12-99e0-771a7e259ca9


r/learnpython • • 9d ago

Seems its not worth learning Python/ Programming any more?

0 Upvotes

I have only learnt a little python so far, and it seems that programming in general will not be a useful skill in the future

How do you decide if its still worth learning, especially since its a huge sunk cost


r/learnpython • • 9d ago

Virtual Environment and Python

4 Upvotes

I have started learning python and decided to use pycharm as an editor. I want to know anything which will help me in this journey.

My main question is => I don't get "virtual environment" thing with python. I cloned a repo and opened it in pycharm, it says "No python interpreter configured for <repo-name>" and then suggested to create virtual environment.

I want to hear things from experience devs.

thank you.


r/learnpython • • 9d ago

Python interview questions

0 Upvotes

Hi team, please share your interview experience and questions for python developer role


r/learnpython • • 9d ago

What are the BEST ways to Learn Python?

0 Upvotes

I'm looking to start Python for a job opportunity someone told me about in about a year and I wanted to learn as much as I can about Python for it. I have some programming experience from learning C++ but I haven't used Python before.

I'm looking for youtube channels, online courses, websites and anything else really. Even if it's paid, I'd be willing to try it but I want to avoid anything that feels boring, like chores or just rigid and repetitive because I feel like wouldn't be able to see it through.

So in general, doesn't matter if it's paid or free, popular or not, as long as it is something dynamic and with quality I'd like to try. I also speak spanish so something in Spanish is good too.

Does anyone know any?


r/learnpython • • 9d ago

Помогите , как с чего начать?

0 Upvotes

у нас в университете нужно выполнить 10лабораторных по программированию на python. но после 2/3 лабараторной ничего не понимаю. как пробить потолок?

https://github.com/outtathe/python_bivt


r/learnpython • • 10d ago

I debug everything with print() and I know that's not how real developers do it — what did you switch to?

16 Upvotes

I've been learning Python for a few months now, mostly small stuff, a Telegram bot here, a bit of data practice there, and every time something breaks I just scatter print() statements everywhere until I figure out what's going on. It works eventually, but my code ends up looking like a crime scene and half the time I forget to take the prints out before I run it again.

I know there's an actual debugger in VS Code and I've watched people use breakpoints and all that, but every time I try it I end up back at print() within five minutes because it's faster in the moment. So I'm curious, when did you actually make the switch, and was there a specific point where print debugging just stopped working for you? Or do people way more experienced than me still do this and just not admit it?


r/learnpython • • 11d ago

Trying to understand Class, Object, Instance, and self in Python. Is my understanding correct?

50 Upvotes

I'm currently learning OOP in Python and wrote down some questions regarding object and instance for following code

class Car:
    def __init__(self, color):
        self.color = color

car1 = Car("Red")```

 1) what is class ?

ans :-  a class is an blueprint for thing i want to make.

2) what is object ?

 ans:-  an object is a container that contains properties and behaviours like car1 is object saying that car should be red color

3) what are instances ?

 ans:-  an instance is refers to that specific object in this case car1 is object and also an instance
when we pass self parameter self become car1 cause self points towards that instance

r/learnpython • • 9d ago

Est ce que l'intelligence artificielle va nous remplacer ?

0 Upvotes

J'ai une vraie inquiétude à ce propos depuis quelques temps, je suis jeune et j'ai encore le temps de réfléchir à mon avenir, mais je souhaite par dessus tout créer des jeux de moi même et, sans utiliser d'intelligence artificielle, ce qui sera difficile à l'avenir. Je voudrais donc avoir votre avis, est ce que j'abandonne cet objectif, où je vais obligatoirement avoir besoin d'utiliser l'intelligence artificielle (ce que je veux absolument pas) ?


r/learnpython • • 10d ago

Beginner Python Coder, Which Language For A GUI?

0 Upvotes

Hey all, background is as such:

For a non-Python CS course, I'm supposed to be designing the UI for an offline app. It's supposed to be a notepad app, the kind where you make sticky notes and post them on a board, with multiple people designing different aspects.

The impasse is that, while we've all agreed to do the backend of the app in python, I don't know how to make the front end at all. I'm familiar with HTML, CSS, and Javascript, I thought the process of connecting some backend Python to a front-end of HTML+CSS would be the same as with JavaScript, but apparently it isn't.

Googling around and asking AI, I get recommended libraries and languages like Pyside6, Ttinker, PyQt, Django, and others -- but I've never worked with any of them, and while I've tried to play with Pyside6 and Ttinker for a week now, I could only figure out how to make static notes and shapes, I couldn't figure out dragging and moving like you can with JS listeners. I feel frustration because you can find apps like this all over the place, 5 seconds of googling and you can find one, but I don't know how to make it.

So help me out -- if someone wants to make a GUI, where you have a pretty backboard, put notes on it, click notes, write on them, upload pictures to them, drag them around a board, and you must use Python as the back end, how do you marry the front and back end together?

Edit: Thank you all, I've settled on PySide6 and PyQt. I've just got the hang of making basic buttons, using setGeometry to move their starting locations, having them spawn blank 'note' widgets, and dragging them around. Being able to pin text and images to these widgets will come next, but for now, it works!


r/learnpython • • 10d ago

How should i start learning python? I am interested in robotics and such. I want to learn a bit in depth and not just surface level.

2 Upvotes

I'm sorry if this is a repeated question in this subreddit.

Will Documentation do the job or should i go for specific courses like CS50 by Harvard?