惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building Strong Python Basics – Loops, Functions and Logic
Vinayagam · 2026-05-26 · via DEV Community
Cover image for Building Strong Python Basics – Loops, Functions and Logic

Vinayagam

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 space between multiple values
  • It moves to the next line after printing

We can control this using sep and end.

  • sep (separator): used to define what comes between values
  • end: used to define what comes at the end of the output

Example:

print("hi", "hello", sep=" ", end="*")
print(5)

Output:

hi hello*5

This means:

  • sep=" " keeps space between words
  • end="*" prevents new line and adds * instead

This concept is useful when formatting output.


Functions in Python

A function is a reusable block of code designed to perform a specific task.

Instead of writing the same logic again and again, we use functions. This improves code readability and reduces duplication.

A function can take input values called arguments and can return output.


Arguments in Functions

Arguments are values passed to a function when it is called.

Types of arguments (basic idea):

  • Required arguments
  • Default arguments
  • Variable-length arguments

Arguments make functions flexible and reusable.


Polymorphism

Polymorphism means “many forms”.

In programming, it means:

  • A single function or operation behaves differently based on input

Example:

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

So, same operation but different behavior.


Method Overloading

Method overloading means:

  • Same function name
  • Different number or type of arguments

Python does not support traditional method overloading like some languages, but we can achieve similar behavior using default arguments or conditions.


Sum of First n Natural Numbers

We learned a mathematical formula:

n(n + 1) / 2

This formula gives the sum of first n numbers.

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

Using loop:

bag = 0 
day = 1
while day <= 10:
    bag = bag + day
    day = day + 1
print(bag)

This loop keeps adding numbers one by one.


Identity Elements in Mathematics

Two important concepts:

  • Additive Identity:
    Adding 0 does not change the value
    Example: 5 + 0 = 5

  • Multiplicative Identity:
    Multiplying by 1 does not change the value
    Example: 5 × 1 = 5

These are basic but important in logic building.


Multiplication of First n Numbers

This is similar to sum, but instead of addition we use multiplication.

total = 1
no = 1
while no <= 5:
    total = total * no
    no = no + 1
print(total)


Factorial Concept

Factorial of a number means multiplying all numbers from 1 to that number.

Example:
5! = 5 × 4 × 3 × 2 × 1

Code:

factorial = 1
no = 1
while no <= 5:
    factorial = factorial * no
    no = no + 1
print(factorial)

Reverse approach:

factorial = 1
no = 5
while no >= 1:
    factorial = factorial * no
    no = no - 1
print(factorial)

Both methods give the same result.


Logic Problem – Frog Climbing

This problem is about simulation using loops.

Given:

  • Frog starts at 50 feet
  • Climbs 2 feet every time
  • Slips down 1.25 feet

We need to find how many steps or days it takes.

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 loop understanding.