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

推荐订阅源

人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
量子位
博客园 - 司徒正美
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
腾讯CDC
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
I
InfoQ
D
Docker
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
宝玉的分享
宝玉的分享
G
Google Developers Blog
GbyAI
GbyAI
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
H
Help Net Security

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
# Day 2: Variables, Data Types & Conditionals in Python —...
Hillary Nart · 2026-05-18 · via DEV Community

By Hillary Nartey | AI Data Specialist in Training

Welcome Back!

This is Day 2 of my Python learning journey. If you missed Day 1, I shared how I got started, the free tools I am using, and why I chose Python as my first programming language.

Today I covered three important Python basics:

  • Variables
  • Data Types
  • Conditionals (if, elif, else)

And the best part? I built a small real-world project to practice everything together!

Variables

A variable is simply a container that stores a value. Think of it like a labeled box where you keep information.

name = "Hillary"
age = 25
price = 9.99

Enter fullscreen mode Exit fullscreen mode

Each of these is a variable. name stores text, age stores a whole number, and price stores a decimal number.

Data Types

In Python, every value has a data type. Here are the basic ones I learned today:

Data Type Example Description
int 25 Whole numbers
float 9.99 Decimal numbers
str "Hillary" Text (string)
bool True / False Yes or No values

You can also tell Python exactly what type a variable should be. For example:

amount: int = int(input("Enter your shopping amount: "))

Enter fullscreen mode Exit fullscreen mode

Here I am telling Python that amount should be an integer, and I am converting the user's input into one using int().

Conditionals (if, elif, else)

Conditionals let your program make decisions. It checks a condition and runs different code depending on whether it is TRUE or FALSE.

The basic structure looks like this:

if condition:
    # do this
elif another_condition:
    # do this instead
else:
    # do this if nothing above is true

Enter fullscreen mode Exit fullscreen mode

My Mini Project: Shopping Discount Calculator 🛒

To practice everything I learned today, I built a simple shopping discount calculator. It takes the amount a customer spends and automatically calculates their discount and final price.

amount: int = int(input("Enter your shopping amount: "))

if amount < 50:
    discount = 0
    print("No discount")
elif amount >= 50 and amount <= 99:
    discount = 0.10
    print("You have 10% discount")
elif amount >= 100 and amount <= 199:
    discount = 0.20
    print("You have 20% discount")
else:
    discount = 0.30
    print("You have 30% discount")

final = amount * (1 - discount)

if final > 150:
    print("You are a big spender")
else:
    print("Great deal")

print(f"Your final price is: ${final}")

Enter fullscreen mode Exit fullscreen mode

How it works:

  • The user enters how much they are spending
  • The program checks which discount range they fall into
  • It calculates the final price after the discount
  • It also checks if the final amount makes them a "big spender."

For example, if you enter $120:

  • You get a 20% discount
  • Your final price becomes $96.00
  • And you get a "Great deal" message!

What I Learned From This Project

Building this small project taught me more than just reading about variables and conditionals. I learned how to:

  • Take user input with input()
  • Convert data types using int()
  • Use multiple conditions with elif
  • Combine conditions using and.
  • Calculate values using arithmetic operators
  • Display results using f-strings like f"Your final price is: ${final}".

Key Takeaways from Day 2

  • Variables store information that your program can use
  • Data types tell Python what kind of information is being stored
  • Conditionals allow your program to make decisions
  • The best way to learn is to build something — even something small!

What's Coming on Day 3?

Next, I plan to cover:

  • Lists — storing multiple values in one variable
  • Loops — repeating actions automatically
  • Another small project to practice!

Thanks for following along! If you are also a beginner, drop a comment below — let's learn together! 🚀

Written by Hillary Nartey | AI Data Specialist in Training