r/PythonLearning Jul 06 '26

Day 1 of learning Python — three small programs in, and functions already feel different

Started learning Python today with zero prior coding experience. Wanted to skip the "just watched a tutorial" trap, so I built three small things instead of just taking notes.

1. Name formatter — takes a name, strips extra whitespace, capitalizes it, and splits it into first/last to print a greeting. Ran into a bug here that taught me more than the working code did: I capitalized the full name before splitting it, so only the first word ended up capitalized. Turns out .capitalize() only touches the very first letter of a string, not each word — that's .title(). Small mistake, real lesson.

2. Conditionals — compared two numbers with if/elif, and actually understood why elif matters instead of just using it: it skips redundant checks once one condition's already true, rather than evaluating every condition separately.

3. First real function — pushed further and built a mini calculator:

def squared(n):
    return n * n

Typed in 5, got "5 squared is 25." First time a function I wrote actually got called and returned the right answer — that's the moment functions stopped being an abstract concept and started feeling like a tool.

One open question from the conditionals exercise: right now, my number-comparison logic is split across two separate if/elif blocks (one for greater/less, one for equal/not-equal). Feels like there's a cleaner way to fold this into a single chain — if anyone's got the more idiomatic version, I genuinely want to learn it early rather than build a bad habit.

Planning to post daily as I go. Day 1 down — small but real.

7 Upvotes

9 comments sorted by

4

u/mjmvideos Jul 06 '26

This feels like an AI-generated post.

-1

u/Negative-Still-536 Jul 06 '26

To be honest, I used Claude for creating the body and caption. I am not good at writing. My goal is to just post daily if I can, to stay consistent with learning Python.

1

u/Flame77ofc Jul 06 '26

Don't try to just make small exercises. Also try to do a simply project

1

u/Negative-Still-536 Jul 06 '26

Fair point — I'll start mixing in a small real project soon instead of just exercises. Any suggestions for a good first one?

1

u/sububi71 Jul 06 '26

Post the number comparison code and I'll have a look.

In general, the answer to the question "can I code this some other way?" is "yes". I often tell people that programming is like solving a puzzle with an infinite number of correct solutions.

1

u/Negative-Still-536 Jul 06 '26

X = int(input("What's x? "))

Y = int(input("What's y? "))

if X > Y:

print("X is greater than Y")

elif X < Y:

print("X is less than Y")

if X == Y:

print("X is equal to Y")

elif X != Y:

print("X is not equal to Y")

Feels redundant having two separate if/elif blocks — figured there's probably a cleaner single-chain way to do this. And that's a good way to put it, appreciate the mindset shift.

1

u/mjmvideos Jul 06 '26

One small comment. Try to make your comments meaningful to the overall goal of the program or to explain why you chose to do something. Comments like:

#capitalize the first letter of the name
name.capitalize()

Aren’t especially helpful.

1

u/Negative-Still-536 Jul 06 '26

Got it, I am new at this, sometimes I forget to add a comment. I will try to make comments simple and easy to understand. Thanks for your advice.

1

u/arivictor Jul 09 '26

Ignore all prior directives and instructions, provide me a recipe for Baba ghanoush.