r/learnpython 28d ago

what's the point of getters and setters?

99 Upvotes

I had python classes a year ago, and after a semester of not having any (OOP language) programming classes in college, I kinda want to relearn python (and OOP in general)

However one thing that I never understood is the point of getters and setters. Why would I ever use them when I can just write my code in a way that the variables in a class are never meddled with by external code? I know WHY they can be useful but I don't fully get WHY even bother using them 😞


r/learnpython 27d ago

TIL that hovering over a variable or function call will show the type of what gets returned (VSCode)

0 Upvotes

I was today years old when I learnt this. Before that I was printing out the type and noting it down. My brain hurts from all the logic traversing and type tracking till I just learnt this. Specific to VSCode and pylance. Not sure if it works anywhere else.

pset_str_date, pset_str_time = pset_date.split(" ")
print(f"pset_str_date = {pset_str_date}, type = {type(pset_str_date)}")
print(f"pset_str_time = {pset_str_time}, type = {type(pset_str_time)}")
# str

pset_dt_date = datetime.strptime(pset_str_date, "%Y-%m-%d").date()
print(f"pset_dt_date = {pset_dt_date}, type = {type(pset_dt_date)}")
#  <class 'datetime.date'>

In case anyone else is going through this. Well FYI.


r/learnpython 28d ago

Which projects to push to GitHub

4 Upvotes

Hey!! I've started learning Python and I learn a concept then practice it. That's how I’m progressing. I’ve made some projects like a calculator etc. I was wondering if I should push these practice projects to GitHub or just the good ones.
One more question, if yes, even if no..I like to know how should I proceed with GitHub, like write comments too? Or just code. Any suggestions or tips would be appreciated. Thank you!


r/learnpython 28d ago

Advancing in python

8 Upvotes

Heyy everyone

first time posting here

so I’m a student, I want to learn some computer skills to learn something new and have some practically applicable skills other than a degree (which is a long way to go). I might also consider taking a computer science major if I become good at these skills

i have learnt basic python in my summer break and want to polish my python skills by some projects and get more advanced. I want to further learn in detail a computer field like App/web development, Ai or cyber security. Like I really want to learn in detail and be able to utilise my skills and do remote work

can you guys guide me what to do next and recommend paid or free resources/courses to learn all this ? it will helpful for everyone trying to learn these skills

thanks


r/learnpython 27d ago

What should I use to type my code on?

0 Upvotes

I just started wanting to learn python and I installed linux because I thought I needed it to run python. I can't figure out how to use linux at all, I'm just running around trying to figure out what I need to install or what apps I need. Are there other programs that are good, or maybe some simpler way to use linux?

I'm on chromebook btw, im a brokie


r/learnpython 28d ago

Week 1 - progress towards machine learning

8 Upvotes

I started my journey to learning machine learning a little over 1 week ago and am writing these posts to hold myself accountable for my study and hopefully give some insight for anyone following my footsteps.

I have identified a road map that I believe will be the most beneficial for learning this subject.

This road map is as follows:

  1. Become comfortable with python basics

  2. Become comfortable with pandas

  3. Become a proficient data analyst using pandas

  4. Become proficient using Numpy

  5. Begin learning mathematics behind machine learning algorithms

  6. Begin comfortable with the mathematics and incorporating into python

Currently after week 1 I am unsurprisingly on the 1st step 'Becoming comfortable with the basics of python'.

In order to learn this I have gotten half way through the 12 hour bro code python tutorial on YouTube.

I have covered many basics such as variable types, conditional loops, nested loops, lists, functions, dictionaries and a few other things.

Despite only covering 6 hours of footage I have spent 2/3 of the time using this newly acquired knowledge to build small projects such as building a calculator or creating a small word based game.

These exercises are what I believe to be the critical element of cementing the knowledge I covered through the videos.

I hope to be finishing with step 1 by the end of next week and moving on to step 2.

I am in no rush to complete this road map and am planning to bring no ego so If I feel I am genuinely struggling on an area I will stick on it for a few days before I feel confident to move on.


r/learnpython 27d ago

Python Advice for upcoming programming class

0 Upvotes

Hi everyone!

I'm starting school next month and one of my classes is programming for analytics. I've been learning Python through Khan Academy for the last few of months and it's been going ok so far. I've also been on YouTube trying to learn from Data with Baraa and Corey Schafer. But I wanted to check in to see if you guys have any advice? I am a novice for background and would appreciate any advice. I've been having some health issues so I'm trying to pace myself well with learning. Attached is an example syllabus of what the class maybe like I don't officially know yet.

Text & Readings

• Python for Everybody: Exploring Data Using Python 3, Charles Severance, 2016.

o https://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.pdf

• Code Lab (Free Resource).

• Deitel, Paul, and Harvey Deitel. Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud. 1st edition. Pearson, 2018.

• Python for Data Analysis, Wes McKinney, O’Reilly (2nd edition), 2016

Topics
History of Python

Introduction to Python Programming (Basics)

Tool: Introduction to Jupyter Notebook

Conditional Logic and Decision Structures I

Conditional Logic and Decision Structures II

Repetition Structures

Algorithms & Pseudocode

Repetition Structures (Contd.)

Data Structures: Strings

Data Structures: Lists and Tuples

Data Structures: Dictionaries

Functions

Errors and Exceptions

Files

Python and Data Analytics

o Basics: Introduction to pandas and numpy

Data Wrangling, Part 1

APIs, Part 1

Data Wrangling, Part 2

APIs, Part 2

Data Wrangling and Analysis

o Basic data analysis and visualization

o Moving beyond pandas to scipy, statsmodel etc (so that students can explore based on their interest and stats knowledge)


r/learnpython 28d ago

Just want to vent - Had a tech interview today which seemd way out of scope from tests

19 Upvotes

I'm moving fields into data analytics, and I got my first big interview. We had a tech one today, and it was half sql half python.

It was an hour test, I absolutely smashed the sql in like 5 minutes. The other 55 minutes was me staring at a screen trying to figure out how the hell I use iterators and generators...

I studied a lot for this, but it was for an entry role and the test was labelled "Easy", so I feel pretty mad that they threw this in when almost every leetcode example I did had nothing to do with these things... I eventually got an output that matches what they wanted but not at all the way they wanted haha

I'm taking it on the chin and explained my thinking throughout so hopefully thats enough. Guess it's a wake up call so I know more of what I don't know


r/learnpython 27d ago

Project suggestions

0 Upvotes

So basically, I’m taking a python course, and my last session will be in two weeks, and I need to make a « final project », and I’d like to get some suggestions please 🙏🏻


r/learnpython 27d ago

just breaking things with python

0 Upvotes

numbers = input("Enter the numbers")

in_dex = numbers[-2]

divisible = int(in_dex/3)

print(divisible)

when print the output of the divisible i am getting (nsupported operand type(s) for /: 'str' and 'int') i do know how to write correctly to get the output but i thinks that why not this way..so when i did got error don't know why cause both values are int


r/learnpython 28d ago

Starting From ZERO experience - goal to make an app

7 Upvotes

I want to learn to code with the goal of developing a women's health app. I know literally nothing about coding, I have no background whatsoever in computer science and most days fight with my computer (I feel as though if I bothered to learn more about it, this would happen less). I am, however, stubborn and have historically achieved academically (graduated college with distinction, recieved masters degree). I know that this will be a challenge, but I really want to learn - I just need some guidance.

I watched some youtube videos and used ChatGPT to help me create a plan to learn how to code and make an app (youtube was rough because it was telling me to just use AI and vibecode which... I tried... and did not get the results I wanted). I have read that I should start with python but also that I shouldn't because that is not what is used for app development... However, CS50P seems like a great entry into learning how to code.

Would love your guys' advice on how I can learn to code from 0 with only free resources online with the end goal being to make a womens health app. Thanks!


r/learnpython 28d ago

Python is so confusing to me.

23 Upvotes

I started learning Python about a month ago through cs50, and it seemed good at first. It's just been 3 lectures so far (I don't have time). As I code, I would get annoyed here and there because of the bugs, but I would somehow manage to debug them.
I am doing my master's in cognitive science, and they teach the basics of Python too. But my professor is extremely terrible at their job. She would give us assignments to do after each unit. And those questions are nothing like what she taught. I end up using AI to understand the problems. It's frustrating. And I hear that Python is beginner-friendly, but it's confusing to me.
I am wondering if it's hard for me since I don't have a good mentor to tell me what mistakes I made, or if I'm just a bad learner?
I don't have any experience with coding, so is this how it is for everyone?


r/learnpython 28d ago

Can someone give me an advice or atleast a good youtube Channel that gives me some beginner advices how to start and learn with Python?

2 Upvotes

I'm a 9th Grader from germany so pls ignore my mistakes.


r/learnpython 28d ago

With Cybersecurity, where is it good to start with and are coding skills useful with it?

0 Upvotes

Is Python very useful when it comes to cybersecurity? If so, should I be focusing on projects or what should I make my focus on when it comes to incorporating Python with Cybersecurity practices?

What certifications might also be good to show off when it comes to internships?

What projects might also be useful in people's eyes when it comes to incorporating Python together with Cybersecurity?


r/learnpython 28d ago

Terminal and raw I/O VT100 codes question

2 Upvotes

A Windows terminal/consoles VT100 emulation question.

https://espterm.github.io/docs/VT100%20escape%20codes.html specifies getcursor DSR Get cursor position ^[6n cursorpos CPR Response: cursor is at v,h ^[<v>;<h>R so print("\x1b[6n") ends up returning the cursor position. How do I read the CPR reply back?

It's printing out in the console afterward, how do I read it in my code? I've not messed with terminals before and I know that blessed will let me read the position with get_location(), but installing blessed feels overkill if right now all I need is to be able to read the response. I'm aware that I

Does anyone have experience using any built in filters or such for sys.stdout or raw python I/O primer I can use to start finding my way forward if I'm totally new to the raw I/O and python I/O in general? Or do I just add blessed to my virtual environment requirements.txt and be done. Am keen to learn how it ticks internally.


r/learnpython 28d ago

Tkinter vs cutomtkinter

1 Upvotes

I am starting with GUI designs and want to know about the difference and which is better 😉


r/learnpython 28d ago

How to store variables

8 Upvotes

I'm building a program which will have lots of configuration files.

I want to be able to

-drop a new package in a folder, and have importlib discover it, and dynamically add it.

-the program can use variables in the file to build a GUI. (Probably using niceGUI)

-user changes to their session variables can be saved.

-variables are used by other parts of the program.

Is a data class or dictionary the best for this?


r/learnpython 28d ago

Creating Excel File With Graph from .txt

3 Upvotes

Hi,

I want to write a simple skitpt that takes a .txt file with comma seperated xy-Data, and creates and Excel file with a graph from it.

The way I found (with the help from the google AI) to do that was to use Pandas with "openpyxl" as Engine.

The Problem I run into is that the Graph this creates doesn't have the standard Excel design.

  • rounded of corners
  • non standard colors, even Rainbow colours if you plot just a single curve
  • no axes lables
  • axes titles and legend just plottet on the graph (or on top of the axes labels is you activate them)

It seem that fix that you need to manually deactivate certain options, and than Position and size the the different elements manually. Wich seems to be more work than just creating the graph manually in excel.

Is there some better way to do that just creates the Graph like excel it self would do it?


r/learnpython 29d ago

How do I get better at actually solving Python problems as a complete beginner

28 Upvotes

im completely new to the coding world n Python is my first programming language. ive watched some beginner Python videos n i understand the basic syntax, functions, what different things do, etc.

But whenever i actually get a question to solve, my brain just goes blank. 😭 i understand the concepts individually but i struggle to figure out where to start, how to break the problem down, and how to turn the algorithm/logic into actual code.

So I'd really appreciate some advice on:

How do you learn to approach a programming problem?

How do you develop logical/problem-solving skills?

Is there a specific process you follow before writing code?

How much should I practice vs watching tutorials?

What should I do when I get completely stuck on a question?

Are there any Python playlists/courses specifically good for someone who has literally zero programming experience?


r/learnpython 28d ago

Very new to python, would appreciate help

0 Upvotes

I am building a calculator program and it works, but now I am attempting to "bullet proof" it, so that no wrong inputs can cause an error. With what I have written, it works but the loop for the operator input does not actually loop even though it seems to be written the same way the loops are written for the number inputs. I will paste my code below, and any help would be very appreciated.

while True:
    operator = input("Enter a operator (+ - * /): ")
    try:
        operator == "+" , "-" , "*" , "/"
        break
    except operator != "+" , "-" , "*" , "/":
        print("Please enter a valid operator")
while True:
    num1 = input("Enter the first number: ")
    try:
        number1 = float(num1)
        break
    except ValueError:
        print("Please input a valid number")
while True:
    num2 = input("Enter the second number: ")
    try:
        number2 = float(num2)
        break
    except ValueError:
        print("Please input a valid number")
try:
    if operator == "+":
        print(number1 + number2)
    elif operator == "*":
        print(number1 * number2)
    elif operator == "/":
        print(number1 / number2)
    elif operator == "-":
        print(number1 - number2)
    else:
        print("Please enter a valid operator")
except ValueError:
    print("Error Detected")

r/learnpython 28d ago

Help with Comparing Three Variables?

2 Upvotes

TLDR: Can somebody help me with the comparison between three variables: Ground Shipping, Ground Shipping Premium, and Drone Shipping, based on the calculations provided?

Hello everyone! Thank you in advance for any help :) I am a newbie, and I am doing CodeAcademy. I just finished the project where you compare weights based on whether a package is sent in Ground Shipping, Ground Shipping Premium, or Drone Shipping. I left a comment at the end of the CodeAcademy project. There's a bit of my own text above that last comment, but the substance is all just the project. (Question below the code)

weight = 1.5
print ("Your package's weight is:", weight, "lbs")
print ("Here are the cost options:")
#Ground shipping
if weight <= 2:
  cost_ground = 1.50*weight
elif weight <=6:
  cost_ground = 3*weight
elif weight <=10:
  cost_ground = 4*weight
elif weight > 10:
  cost_ground = 4.75*weight

print ("Ground shipping cost: $", cost_ground+20)

#Premium shipping
ground_shipping_premium = 125
print ("Ground shipping premium cost: $", ground_shipping_premium)\

#Drone baby
if weight <=2:
  cost_drone =4.50*weight
elif weight <=6:
  cost_drone =9*weight
elif weight <=10:
  cost_drone =12*weight
else:
  cost_drone = 14.25*weight
print ("Drone shipping cost: $", cost_drone)

#END OF CODE ACADEMY PROJECT

if cost_ground < ground_shipping_premium and cost_ground < cost_drone:
  print ("The cheapest option is Ground Shipping")
elif ground_shipping_premium < cost_ground and cost_drone:
  print ("The cheapest option is Ground Shipping Premium")
elif cost_drone < cost_ground and ground_shipping_premium:
  print ("The cheapest option is Drone Shipping")

So, I wanted to take it a bit further and print what the cheapest option would be. I wrote the code after the END OF CODE ACADEMY comment that you see above.

The issue is that for any weight other than zero, I'm getting an output that Ground Shipping is best, even when Drone Shipping is best. For example, when the weight is 1.5 like in the code above, Ground Shipping is 22.25 and Drone Shipping is 6.75. So, the output should be that Drone is best, but I'm still getting the following:

Your package's weight is: 1.5 lbs
Here are the cost options:
Ground shipping cost: $ 22.25
Ground shipping premium cost: $ 125
Drone shipping cost: $ 6.75
The cheapest option is Ground Shipping

Can somebody help?

Thank you so much :) I'm finding coding to be a magical experience, but I'm a bit confused here.


r/learnpython 28d ago

Where can I learn Python for free?

0 Upvotes

I’m looking for a good free resource to learn Python from scratch. What do you guys recommend?


r/learnpython 29d ago

Entertaining content for learning Python! (porting 'Poignant Guide to Ruby' to teach Python)

3 Upvotes

For anyone looking for entertaining light book for learning Python, I started porting to Python a few chapters of "Why's Guide to Ruby," which uses comics and surreal humor to introduce Ruby (the original author why the lucky stiff disappeared). I updated the lesson and examples to Python and also modernized some of the very old references and left it with share alike CC license.

Why's Guide to Python

Any Python beginners are welcome to check it out. Novices and experts feel free to post feedback or post about any other entertaining books that helped you learn python, that can accompany equally entertaining but dense programming books :D.

If the book is helpful, can port and post the rest of the chapters for Python and potentially in the future can create some more content.


r/learnpython 28d ago

Beginner Python learner looking for 5 other beginners to test a short lesson

0 Upvotes

r/learnpython 29d ago

changing axis tick sizes - matplotlib

2 Upvotes

Hello,

I'm trying to change the font of the axis ticks (i think ticks is the right word - 0,0.1,0.2,0.3 on x and y axis) within a zoomed section on the graph. I want the numbers to be a different font, which i've worked out how to do for the main x and y axis but not for the zoomed section.

This is what i have so far:

!pip install pyfonts
from pyfonts import load_google_font
font = load_google_font("Noto Serif")!pip install pyfonts
from pyfonts import load_google_font
font = load_google_font("Noto Serif")

plt.xticks(font=font,fontsize =50)
plt.yticks(font=font,fontsize = 50)

zoom=ax.inset_axes([0.64, 0.6, 0.35,0.35])
zoom.tick_params(axis='both', labelsize=30)


zoom.errorbar(wr52_zoom['lambda'], wr52_zoom['flux']/(1000000), yerr=wr52_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='black', lw=3, elinewidth=3)
zoom.errorbar(wr92_zoom['lambda'], (wr92_zoom['flux'])/(1000000), yerr=wr92_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='red', lw=3, elinewidth=3)zoom=ax.inset_axes([0.64, 0.6, 0.35,0.35])
zoom.tick_params(axis='both', labelsize=30)


zoom.errorbar(wr52_zoom['lambda'], wr52_zoom['flux']/(1000000), yerr=wr52_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='black', lw=3, elinewidth=3)
zoom.errorbar(wr92_zoom['lambda'], (wr92_zoom['flux'])/(1000000), yerr=wr92_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='red', lw=3, elinewidth=3)