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

推荐订阅源

罗磊的独立博客
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
C
Check Point Blog
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG

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
Mastering the print() Function in Python
Mary Nyandia · 2026-05-28 · via DEV Community

When learning Python, one of the very first functions you’ll use is print(). It may look simple, but it’s incredibly powerful and flexible. On Day 3 of my Python journey, I decided to dive deeper into how print() works and all the ways you can use it.

✨ What is print()?
The print() function displays information on the screen. It can show text, numbers, variables, or even complex data structures. Think of it as your program’s way of “talking back” to you.

1.Printing Text
The simplest use of print() is to display text. By wrapping words in quotes, Python knows you want to show them exactly as written. For example:

print("Hello, Python!")

Enter fullscreen mode Exit fullscreen mode

Output: Hello, Python!

2. Printing Variables
Variables store data, and print() lets you see what’s inside them.

name = "Mary"
age = 28
print("Name:", name)
print("Age:", age)

Enter fullscreen mode Exit fullscreen mode

Output: Name: Mary Age: 28

3. Printing Multiple Items
Sometimes you want to display several things at once. print() allows you to pass multiple items separated by commas. For example:

print("Python", "is", "fun")

Enter fullscreen mode Exit fullscreen mode

Output: Python is fun.
Python automatically adds spaces between items, so you don’t need to worry about formatting them manually.

4.Using f‑strings (Formatted Strings)
F‑strings are one of Python’s most powerful features for printing. They let you embed variables directly inside text using curly braces {}. For example:

name = "Mary"
age = 28
print(f"My name is {name} and I am {age} years old.")

Enter fullscreen mode Exit fullscreen mode

Output: My name is Mary and I am 28 years old.
F‑strings make your output cleaner and easier to read compared to using commas.

5. Special Parameters in print()
The print() function has optional arguments that give you more control:

  • (sep) changes the separator between items. For example:
print("Python", "is", "fun", sep="-") 

Enter fullscreen mode Exit fullscreen mode

Outputs: Python-is-fun.

  • (end) changes what happens at the end of the line. By default, print() ends with a new line, but you can override it:
print("Hello", end=" ")
print("World")

Enter fullscreen mode Exit fullscreen mode

Output: Hello World on one line

  • (file) lets you send output to a file instead of the screen, which is useful for logging.

6. Escape Characters
Escape characters let you format text in special ways. For example, \n creates a new line, and \t adds a tab space.

print("Line1\nLine2")
print("Tab\tSpace")

Enter fullscreen mode Exit fullscreen mode

Output:

Line1
Line2
Tab    Space

Enter fullscreen mode Exit fullscreen mode

These little tricks make your output more readable and professional.

🎯My Take
The print() function may look simple, but it’s incredibly versatile. From showing text and variables to formatting output with f‑strings, separators, and escape characters, mastering print() early will make your Python journey smoother. It’s not just about displaying information , it’s about communicating clearly with your code.