r/learnpython • • Apr 19 '26

what is a set with duplicate values called

2 Upvotes

If I have:

myAwesomeSet = {"Strait of Hormuz", "Strait of Gibralter", "Bering Strait", "Strait of Hormuz"}

And test: myAwesomeSet == type(set()) python evaluates ts to false. But then what class is it? Imo t'would make more sense for an error or sum cuz what would the difference between a set w/two values and a list be? Are there any usage differences?


r/learnpython • • Jul 14 '26

Reviews on "The Complete python bootcamp from zero to hero in Python"

2 Upvotes

There's a course on udemy named "The Complete python bootcamp from zero to hero in Python by Jose Portilla, Pierian Training".
if anyone done this is it good? I will be getting this for free (from someone else account but ofc not certificate)
Or BroCode, fcc, or CS50P (2023, cause that's free on yt)


r/learnpython • • Oct 09 '25

I'd like to create a fairly advanced game in Pygame.

2 Upvotes

I'd like to create a fairly advanced game in Pygame. So far, I've had some experience with simple games, but the problem is that I've stopped them all due to bugs I couldn't fix. Is there a basic structure I should follow? Can someone explain it to me?


r/learnpython • • Aug 09 '26

Beginner Python here:Need help understanding how to find min, max, and duplicates using for range loops

2 Upvotes

I’m a beginner learning Python and I’m having trouble figuring out how to approach this assignment. I’m not necessarily looking for someone to just give me the answer. I’d like help understanding the logic and how to build it.

The assignment is to create a Python program that:

Asks the user to enter 10 integers
Stores all 10 integers in a list
Finds the maximum and minimum numbers
Finds any duplicate numbers
Prints "No duplicate" if there aren’t any duplicates
Uses for loops with range() for the input, min/max determination, and duplicate identification
Does not use Python’s built-in min() or max() functions
Does not use def/user-defined functions
Tries to use as few loops as reasonably possible

Input:
10, 5, 20, 10, 5, 15, 7, 1, 30, 15
Output:
Max is 30
Min is 1
Duplicates: 10 5 15

Thank you whoever responds. :)


r/learnpython • • Nov 25 '25

Why this regex is not removing the parenthesis and everything in it. I asked the gemini and he said this regex is perfectly fine but its not working. Can anyone state a reason why is that? Thankyou in advance!

0 Upvotes
####
tim = "Yes you are (You how are you)"
tim.replace(r"\(.*\)", "") 

Yes you are (You how are you)
####

r/learnpython • • Aug 19 '26

Type Error: 'bool' object is not iterable - what is this error and how can I solve it?

0 Upvotes

I have some code with a function restock_warehouse, that adds to the current stock 5 times while the current stock is smaller than the target stock. My question is, how can I fix the function so that the code works properly with and the print() call is displayed in the terminal?

The error message I have been receiving is:

```

Traceback (most recent call last):

File "file_name", line 15, in <module>

final_stock = restock_warehouse(10, 25)

File "file_name", line 5, in restock_warehouse

for i in range(5) and current_stock < target_stock:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: 'bool' object is not iterable

```

I have already tried wrapping the conditional part of the loop in parentheses, but it hasn't worked and I don't exactly understand the error message.

Version information: I'm on Python 3.9.6

def restock_warehouse(current_stock, target_stock):
    print("Starting warehouse restock system...")


    # We want to keep adding items until we reach our target stock
    for i in range(5) and current_stock < target_stock:
        print(f"Current inventory level: {current_stock}")


        current_stock == current_stock + 5


    print("Warehouse restock complete!")
    return current_stock



# Start with 10 items, target goal is 25 items
final_stock = restock_warehouse(10, 25)
print(f"Final stock total: {final_stock}")

r/learnpython • • Aug 07 '26

Harvard's CS50P vs University of Helsinki Python MOOC, which one should I actually do?

0 Upvotes

Trying to decide between Harvard’s CS50P and the University of Helsinki’s Python MOOC.

I’m halfway through UoH’s Java MOOC and really like its hands-on, exercise-heavy approach. For Python, though, I’m confused whether I should go with the learning style I already enjoy (UoH) or choose CS50P for the potential resume/certification value of the Harvard name.

For those who’ve done either/both:

- Does CS50P’s certificate actually help with recruiters?

- Is UoH Python noticeably more rigorous?

- Would you do both, or pick one?


r/learnpython • • Sep 15 '26

When did Python finally start to “click” for you?

1 Upvotes

Was it after building a real project, solving coding problems, learning OOP, working with APIs, or simply practicing consistently?


r/learnpython • • Oct 25 '26

Why parameters finally made sense to me today

0 Upvotes

Hey everyone, just wanted to share a quick lightbulb moment I had with Python today about why functions actually need parameters.

At first, I didn't get why we couldn't just write functions without them. But it clicked today: parameters are basically just empty placeholder slots so your function can handle changing data.

Without a Parameter (Fixed)

It can only ever do one exact thing:

Python

def greet():
    print("Hello, Alice!")

greet()  # Always prints "Hello, Alice!"

With a Parameter (Dynamic)

Adding name gives you a slot inside the function. When you call it, you just pass whatever data you want into that slot:

Python

def greet(name):
    print(f"Hello, {name}!")

greet("Alice")  # Prints: Hello, Alice!
greet("Bob")    # Prints: Hello, Bob!

My main takeaway: If the code inside your function needs to work with different information every time, you need a parameter to pass that data in from the outside!


r/learnpython • • Mar 27 '26

Which programming language should I learn this summer at 13? Need advice

0 Upvotes

I need some advice. I’m only 13 years old, and this summer I’m going to stay with my grandparents for 2 months. They don’t have internet, and I will only have mobile internet. I would like to learn the basics of another programming language. I already know Python and the basics of Java and Rust.

I would like to learn something else. I was thinking maybe Java, to make mobile apps, or C# to make games in Unity. I have a dream to create a game similar to Hello Neighbor.

I also thought about learning C++, since it is popular on TikTok, although I already know the basics of Rust and I’m not sure if learning C++ would be useful for me.

What should I choose?

Update: I've been programming for about 3 years now. When I was 10, I tried to enroll in programming courses, but at first they didn't want to accept me because of my age. However, after I demonstrated my knowledge, they saw that my level was quite good.

Since then, I've continued to learn. I already have some practical experience

For me, programming is not just a hobby - I want to develop real skills and work in this field in the future.


r/learnpython • • Mar 25 '25

TIL Python recommends you use snake_case instead of camelCase for variables

0 Upvotes

Apologies if this is a "low quality" post or something frequently brought up, but thought I'd share in the spirit of shared learning.

I started off programming in VB, Java, C++ and the convention I was taught/saw everyone using was camelCase.

As I've dipped my toe further into Python and started looking into the actual code of my favorite libraries on Github, I noticed that they were all using snake_case whenever possible. Upon further research, it seems PEP8 advocates for snake_case (unless for backward compatability).

I'm sure smarter people than me have argued over which is more readable (snake_case vs camelCase) so I won't chime in on this. To me, this is just a convention and it's more important to pick whatever works best for your purposes (i.e. if you're going to be contributing to open source Python projects, maybe stick with snake_case).

In the same vein, I also have been reading a bit about spaces between equal signs and variables in declarations vs use in arguments suffice to say that is a separate topics.


r/learnpython • • Sep 05 '24

Is python recommended for coding games?

0 Upvotes

Because I think it’s only good for coding like websites or some shit if it is recommended for coding games, sign me up where do I start because I’m starting out coding and programming


r/learnpython • • Oct 11 '22

What's with all the downvotes???

0 Upvotes

I was scrolling this sub yesterday and so many questions were downvoted to 0... so many legit comments downvoted... Must be quite discouraging and unhelpful for people coming here for help and to learn.


r/learnpython • • May 17 '23

Is it normal that after 2 years of using python, I still forgot the colon?

7 Upvotes

When I create a function (or a condition), 1/3 of the time, I forgot the colon. Is it normal or am I a dumb programmer?


r/learnpython • • Apr 22 '26

Is there even a point to learning python anymore?

0 Upvotes

After seeing what AI can do, as a beginner I feel so demotivated and it feels pointless to learn python to me, as someone who is trying to pick it up as a secondary skill. What do you guys think?


r/learnpython • • Jan 20 '26

How can i can learn Python?

3 Upvotes

Hi everyone, I'm new in coding and i chose the python for a first language, but actually know nothing .How can I start learn it's effectivly , maybe someone know any courses or youtube channels?


r/learnpython • • Sep 08 '25

Explain This Code

0 Upvotes

students = {"Frank": 85, "Monica": 72, "Steve": 90} print(max(students, key=students.get))

Can you explain this code in simple terms or to 10 years old guy I can't understand this (key=students.get) Can you explain what is the purpose and use of (key=students.get) this.


r/learnpython • • Sep 23 '25

Why does 7:45 give 7.75 but 12:45 gives 12.7499999999 ?

0 Upvotes

I wrote this small Python function to convert HH:MM into hours as a decimal:

inp = input("HH:MM ? ")

def convert(time):
    t = float(time.replace(":", "."))
    hours = int(t)
    minutes = (t - hours) * 100
    print(hours + minutes / 60)

convert(inp)

When I enter 7:45, it prints 7.75 (perfect).
But when I enter 12:45, it prints 12.749999999999998.

Why does Python get it right in the first case but not the second? Aren’t both calculations basically the same?

(I KNOW A BETTER WAY TO DO IT IS THROUGH SPLIT BUT I WA JUST TRYING TO TEST IT OUT )
(ALSO I CAN ROUND OFF MINUTES TO TWO DECIMAL AND JUST GET THE CORRECT ANSWER BUT I AM INTEREST IN THE WORKING OF PYTHON AND WHY IT DOES THAT )


r/learnpython • • Jan 19 '26

Why does Python sometimes say a variable is undefined when I just used it?

0 Upvotes

I keep running into errors where Python says a variable isn’t defined, even though I thought I created it earlier.

I’m guessing this has something to do with functions or scope, but it hasn’t fully clicked yet.
Any beginner-friendly explanations or mental models?


r/learnpython • • Jan 27 '26

Need advice: how to hide Python code running in a Docker container?

3 Upvotes

I have a Docker container with Python code. It’s a server with propriety code in it which I would like to hide.

I need to deploy the container as an on-premise solution for time optimisation but I don’t want the user to be able to see the Python code.

Is there a way to achieve this for production-grade systems?


r/learnpython • • Nov 07 '24

Wondering how long it takes to iterate 10e20 times

3 Upvotes

Hey everyone,

I'm pretty new to programming and for exercise i wrote a rock, paper, scissors program.
As I always use Rock because rock always wins I had the idea to test my statement.
So i thought why, instead of typing, not just set my weapon to rock and iterate 10e20 times over it (don't know the english word for this number so yeah)

As for now I'm probably waiting like 20 minutes for the program to finish. Does anyone maybe know how long it will take approximately ?


r/learnpython • • Jan 02 '25

Is there function like 'Update()' that is called every X ms?

1 Upvotes

Hi, i just started learning py and i need to check if hardware button is pressed. I have 'while True:' setup but then any function beneath that while dosent work 'it isnt defined'

Im coming from Unity C#


r/learnpython • • Dec 17 '24

I am trying to get a option to put in a answer in my code that gives a diffrent output based on which if else statement is true. Why wont it work?

0 Upvotes

I'm beginner in coding and was practicing by myself. below is the code i wrote.

    print("the result of the operation is", sum)

    input_answer=input ("give the correct answer to see if you are worthy: ")

    magic=1000000000
    skill_level=0
    sum= magic*skill_level
    print(sum)

    if sum< 1:
        print("you are not worthy")
    else:
        print("You are worthy")

r/learnpython • • Jan 11 '25

What are some good use cases of python?

1 Upvotes

Hello. I started learning python a bit ago as an introductory language to get a job when I’m older. I’m curious as to what are some good use cases of it/what you can program with it?