The print() Function in Python
Nerd Cafe | نرد کافه
The print() function displays information to the console (or another output stream). It’s very common in debugging, reporting results, and logging progress.
Syntax
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)*objects
One or more items to print
sep
Separator between items (default: space " ")
end
What to add at the end (default: newline "\n")
file
Where to send output (default: console)
flush
Force immediate writing (useful for live updates)
Step-by-Step Examples
1. Basic Output
print("Hello, World!")Output:
Hello, World!2. Printing Variables
model = "RandomForest"
accuracy = 94.5
print("Model:", model)
print("Accuracy:", accuracy)Output:
3. Custom Separator (sep)
sep)Output:
Useful when printing multiple metrics side by side.
4. Stay on the Same Line (end)
end)Output:
Helpful for progress display.
5. Mixing Data Types
Output:
Good for debugging variables.
6. f-Strings (Recommended for Professional Logging)
Output:
Clean, readable, and widely used in machine learning logs.
7. Video Tutorial
💖 Support Our Work
If you find this post helpful and would like to support my work, you can send a donation via TRC-20 (USDT). Your contributions help us keep creating and sharing more valuable content.
TRC-20 Address: TAAVVf9ZxUpbyvTa6Gd5SGPmctBdy4PQwf
Thank you for your generosity! 🙏
Keywords
print(), syntax, arguments, objects, sep, end, file, flush, console, variables, strings, data types, formatting, logging, debugging, nerd cafe , نرد کافه
Channel Overview
🌐 Website: www.nerd-cafe.ir
📺 YouTube: @nerd-cafe
🎥 Aparat: nerd_cafe
📌 Pinterest: nerd_cafe
📱 Telegram: @nerd_cafe
📝 Blog: Nerd Café on Virgool
💻 GitHub: nerd-cafe
Last updated