Building Strong Python Basics – Loops, Functions and Logic

Published: (May 25, 2026 at 12:37 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for Building Strong Python Basics – Loops, Functions and Logic

My Learning Notes – Python Basics (Day Learning Blog)

Today’s class was focused on basic Python concepts and some logical problems. Even though the topics are simple, they form the foundation for programming. I am writing this blog to revise what I learned in my own words.

sep and end in Python

In Python, the print() function has default behavior:

  • It adds a space between multiple values.
  • It moves to the next line after printing.

We can control this using sep and end.

  • sep (separator): defines what comes between values.
  • end: defines what comes at the end of the output.
print("hi", "hello", sep=" ", end="*")
print(5)

Output

hi hello*5
  • sep=" " keeps a space between words.
  • end="*" prevents a new line and adds * instead.

Functions in Python

A function is a reusable block of code designed to perform a specific task. Instead of writing the same logic repeatedly, we use functions to improve readability and reduce duplication. Functions can take input values called arguments and can return output.

Arguments in Functions

Arguments are values passed to a function when it is called. Basic types of arguments:

  • Required arguments
  • Default arguments
  • Variable‑length arguments

Arguments make functions flexible and reusable.

Polymorphism

Polymorphism means “many forms”. In programming, a single function or operation can behave differently based on its input.

  • Adding two numbers → numeric addition
  • Adding two strings → string concatenation

The same operation, different behavior.

Method Overloading

Method overloading refers to having the same function name with different numbers or types of arguments. Python does not support traditional method overloading, but similar behavior can be achieved using default arguments or conditional logic.

Sum of First n Natural Numbers

The mathematical formula:

[ \frac{n(n + 1)}{2} ]

gives the sum of the first n natural numbers.

Example: For n = 10,
Sum = 10 × 11 / 2 = 55

Using a Loop

bag = 0
day = 1
while day = 1:
    factorial = factorial * no
    no = no - 1
print(factorial)

Both methods produce the same result (120).

Logic Problem – Frog Climbing

A simulation using loops.

Problem:
A frog starts at 50 feet, climbs 2 feet each attempt, then slips down 1.25 feet. Determine how many steps (or days) it takes to reach the ground.

feet = 50
up = 2
down = 1.25
day = 0

while feet > 0:
    feet = feet - up + down
    day = day + 1

print(day)

This type of problem improves logical thinking and understanding of loops.

0 views
Back to Blog

Related posts

Read more »

Go Error Handling: Annoying or Awesome?

For weeks when I was completely new to coding, I kept wondering, “What did I get myself into?” I barely understood what I was looking at whenever I came across...