{"id":7996,"date":"2021-01-25T16:50:44","date_gmt":"2021-01-25T11:20:44","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=7996"},"modified":"2026-07-16T08:31:36","modified_gmt":"2026-07-16T12:31:36","slug":"how-to-use-the-python-print-function-to-print-objects","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/how-to-use-the-python-print-function-to-print-objects\/","title":{"rendered":"How to Use the Python Print Function to Print Objects"},"content":{"rendered":"\n<p>The Python Print Function displays text, numbers, variables, collections, and custom objects by converting them into readable output. Put one or more values inside <code>print()<\/code>, and Python sends the result to the console by default.<\/p>\n\n\n\n<p>Simple? Yes. Limited? Not really. Once you move beyond \u201cHello, World!\u201d, the Python Print Function becomes a practical tool for formatting messages, checking program flow, inspecting API data, and understanding how your own <a href=\"https:\/\/www.h2kinfosys.com\/courses\/python-online-training\/\">Python certification online<\/a> classes behave.<\/p>\n\n\n\n<p>I still use print statements when exploring unfamiliar data. They are not a substitute for logging, but one carefully placed line can quickly expose a stubborn loop or unexpected value.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"563\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-1024x563.png\" alt=\"\" class=\"wp-image-42712\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-1024x563.png 1024w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-300x165.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-768x422.png 768w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-1536x845.png 1536w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3-150x82.png 150w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2021\/01\/image-3.png 1691w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Syntax of the Python Print Function<\/h2>\n\n\n\n<p>The standard form is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(*objects, sep=\" \", end=\"\\n\", file=None, flush=False)<\/pre>\n\n\n\n<p><code>objects<\/code> are the values to display. Python places <code>sep<\/code> between them, adds <code>end<\/code> afterward, and normally writes to standard output. Because <code>print()<\/code> is built in, no import is needed.<\/p>\n\n\n\n<p>Here is the smallest useful example of the Python Print Function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(\"Hello, Python!\")<\/pre>\n\n\n\n<p>You can also print numbers and Boolean values directly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(42)\nprint(3.14159)\nprint(True)<\/pre>\n\n\n\n<p>Beginners sometimes assume every value needs <code>str()<\/code>. Usually, it does not. The Python Print Function performs the ordinary string conversion for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Printing Multiple Objects<\/h2>\n\n\n\n<p>A common real-world use is displaying several related values on one line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">student = \"Maya\"\nscore = 92\npassed = True\n\nprint(\"Student:\", student, \"Score:\", score, \"Passed:\", passed)<\/pre>\n\n\n\n<p>The Python Print Function inserts spaces between objects by default. For output meant to be read by another person, an f-string is often cleaner:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(f\"Student: {student} | Score: {score} | Passed: {passed}\")<\/pre>\n\n\n\n<p>I use commas for quick debugging and f-strings for cleaner, reader-facing output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use <code>sep<\/code> to Control the Separator<\/h2>\n\n\n\n<p>The <code>sep<\/code> argument changes what appears between objects, allowing the Python Print Function to create dates, paths, labels, or compact rows.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(\"2026\", \"07\", \"16\", sep=\"-\")\nprint(\"python\", \"training\", \"online\", sep=\"\/\")<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2026-07-16\npython\/training\/online<\/pre>\n\n\n\n<p>You can even sketch a CSV-style row:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(\"Keyboard\", 2, 49.99, sep=\",\")<\/pre>\n\n\n\n<p>For real <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\" rel=\"nofollow noopener\" target=\"_blank\">CSV files<\/a>, use the <code>csv<\/code> module, which handles quoting and embedded commas correctly. The Python Print Function still works well for prototypes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use <code>end<\/code> to Stay on the Same Line<\/h2>\n\n\n\n<p>Every call normally finishes with a newline. Change <code>end<\/code> when the next output should continue on the same line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for step in range(1, 4):\n    print(f\"Step {step}\", end=\"... \")\n\nprint(\"done\")<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Step 1... Step 2... Step 3... done<\/pre>\n\n\n\n<p>This use of the Python Print Function works for progress indicators and countdowns. Some environments buffer output, so text may not appear immediately.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use <code>flush=True<\/code> for Immediate Output<\/h2>\n\n\n\n<p>Set <code>flush=True<\/code> when visible timing matters:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import time\n\nfor seconds in range(3, 0, -1):\n    print(seconds, end=\" \", flush=True)\n    time.sleep(1)\n\nprint(\"Go!\")<\/pre>\n\n\n\n<p>The Python Print Function is used this way in lightweight deployment scripts, containers, and monitoring commands where delayed output would be confusing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Printing Lists, Dictionaries, Tuples, and Sets<\/h2>\n\n\n\n<p>Built-in collections can be printed directly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">skills = [\"Python\", \"SQL\", \"Git\"]\nprofile = {\"name\": \"Asha\", \"experience\": 2}\ncoordinates = (18.52, 73.85)\npermissions = {\"read\", \"write\"}\n\nprint(skills)\nprint(profile)\nprint(coordinates)\nprint(permissions)<\/pre>\n\n\n\n<p>The Python Print Function uses each object\u2019s string representation. For deeply nested structures, use <code>pprint<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from pprint import pprint\n\nproject = {\n    \"name\": \"Sales Analyzer\",\n    \"team\": [\"Asha\", \"Leo\", \"Nina\"],\n    \"settings\": {\"region\": \"us-east\", \"debug\": True, \"retries\": 3}\n}\n\npprint(project, sort_dicts=False)<\/pre>\n\n\n\n<p><code>pprint()<\/code> does not replace the Python Print Function; it simply formats complex structures with more visual organization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Printing JSON Clearly<\/h2>\n\n\n\n<p>API responses are easier to inspect when they are indented:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import json\n\nresponse = {\n    \"status\": \"success\",\n    \"records\": 3,\n    \"items\": [\"A12\", \"B07\", \"C31\"]\n}\n\nprint(json.dumps(response, indent=2))<\/pre>\n\n\n\n<p>Here, the Python Print Function displays the formatted string from <code>json.dumps()<\/code>. Indented API data is much easier to inspect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Printing Custom Objects with <code>__str__<\/code><\/h2>\n\n\n\n<p>Consider a simple class:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Course:\n    def __init__(self, name, duration):\n        self.name = name\n        self.duration = duration\n\ncourse = Course(\"Python Automation\", \"8 weeks\")\nprint(course)<\/pre>\n\n\n\n<p>The default result may be a memory-oriented object description. To make the Python Print Function show something meaningful, define <code>__str__<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Course:\n    def __init__(self, name, duration):\n        self.name = name\n        self.duration = duration\n\n    def __str__(self):\n        return f\"{self.name} ({self.duration})\"<\/pre>\n\n\n\n<p>Now <code>print(course)<\/code> displays:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python Automation (8 weeks)<\/pre>\n\n\n\n<p>The Python Print Function depends on an object\u2019s string representation, so thoughtful class design improves debugging and command-line output. Add <code>__repr__<\/code> for a developer-focused representation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending Output to a File<\/h2>\n\n\n\n<p>The <code>file<\/code> argument lets the Python Print Function write to a file-like object:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">with open(\"report.txt\", \"w\", encoding=\"utf-8\") as report:\n    print(\"Daily processing completed\", file=report)\n    print(\"Records processed:\", 1284, file=report)<\/pre>\n\n\n\n<p>This works for small reports. In production, use <code>logging<\/code> for timestamps, severity levels, filtering, and rotation. Print is best for exploration and command-line output; logging is better for maintained systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes Beginners Make<\/h2>\n\n\n\n<p>One common error is using old Python 2 syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print \"Hello\"<\/pre>\n\n\n\n<p>Modern Python 3 requires parentheses. Another mistake is combining text and a number with <code>+<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">age = 28\nprint(\"Age: \" + age)  # TypeError<\/pre>\n\n\n\n<p>Use a comma, <code>str(age)<\/code>, or an f-string instead:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(\"Age:\", age)\nprint(f\"Age: {age}\")<\/pre>\n\n\n\n<p>A third mistake is printing a function rather than calling it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def total():\n    return 25\n\nprint(total)    # function object\nprint(total())  # 25<\/pre>\n\n\n\n<p>The Python Print Function is correct in both cases; the supplied object is different.<\/p>\n\n\n\n<p>Never leave passwords, API keys, access tokens, payment details, or private customer data in debug output. Shared terminals and logs can turn a convenient statement into a security incident.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why This Skill Still Matters in 2026<\/h2>\n\n\n\n<p>Python 3.14 was released on October 7, 2025, and Python.org listed Python 3.14.6 as the current maintenance release in June 2026. The 3.14 series also brought official support for free-threaded Python, along with interpreter and command-line improvements.<\/p>\n\n\n\n<p>Even with those advanced changes, the Python Print Function remains relevant. Developers still need readable output while checking concurrent tasks, AI pipelines, test automation, API responses, and data-processing jobs. The real skill is knowing what to print and when to replace temporary output with tests, a debugger, or structured logging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learn Python Through Practical Training<\/h2>\n\n\n\n<p>A structured python certification course can help when self-study becomes scattered. Reading syntax is useful, but building a complete script, finding the bug, and explaining the fix is where the learning starts to stick.<\/p>\n\n\n\n<p>H2K Infosys promotes a job-focused Python program with live learning, practical assignments, and real projects. Its current course page describes beginner-friendly instruction designed by certified trainers and places hands-on experience at the center of the program. That matters when comparing a <a href=\"https:\/\/www.h2kinfosys.com\/blog\/tag\/python-online-course-certification\/\" data-type=\"post_tag\" data-id=\"1584\">Python online course certification<\/a> because the certificate is evidence of completion; the real value is the ability to build and explain working code.<\/p>\n\n\n\n<p>When choosing the best python certification for your goals, look beyond the badge. Check for instructor feedback, realistic projects, debugging practice, interview preparation, and portfolio work you can discuss confidently. H2K Infosys also publishes course features that include completion certification, resume preparation, mock interviews, and placement support in its Python training options.<\/p>\n\n\n\n<p>For anyone searching for Python certification online, ask one blunt question: will this program make me write code regularly? Passive watching feels productive, but the confidence disappears when you face a blank editor. Guided practice, code reviews, and project work close that gap, and that is where H2K Infosys\u2019s practical emphasis can be useful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Takeaway<\/h2>\n\n\n\n<p>The Python Print Function starts as a one-line command and grows into a flexible tool for formatting output, inspecting objects, understanding program flow, and communicating results. Learn its parameters, practice with collections and classes, and build the judgment to move from print statements to proper logging as your projects mature.<\/p>\n\n\n\n<p>Google\u2019s current Search and AI-feature guidance emphasizes helpful, reliable, people-first content rather than pages created mainly to manipulate rankings. The same principle fits technical learning: practical examples and genuine understanding beat empty repetition.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1784201904683\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is <code>print()<\/code> used for in Python?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>It displays one or more objects as text. Developers use it for user messages, quick debugging, terminal output, and simple file writing.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784201927544\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Can <code>print()<\/code> display any Python object?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>It can display nearly any object through that object\u2019s string representation. Custom classes can define <code>__str__<\/code> and <code>__repr__<\/code> to make the result clearer.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784201943825\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is the difference between <code>sep<\/code> and <code>end<\/code>?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p><code>Sep<\/code> controls what appears between multiple objects. <code>end<\/code> controls what appears after the last object, with a newline used by default.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784201987928\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Should I use print or logging?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use print for learning, small scripts, and temporary debugging. Use logging for production software that needs timestamps, severity levels, filtering, rotation, or centralized monitoring.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784202004112\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I print without starting a new line?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Set <code>end<\/code> to an empty string or another value, such as <code>print(\"Loading\", end=\"\")<\/code>. Add <code>flush=True<\/code> when the message must appear immediately.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784202016929\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Is H2K Infosys suitable for learning Python?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>H2K Infosys presents its Python training as beginner-friendly, job-focused, and project-based. Review the current curriculum, trainer access, project scope, schedule, support terms, and certification details before enrolling.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>The Python Print Function displays text, numbers, variables, collections, and custom objects by converting them into readable output. Put one or more values inside print(), and Python sends the result to the console by default. Simple? Yes. Limited? Not really. Once you move beyond \u201cHello, World!\u201d, the Python Print Function becomes a practical tool for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":42716,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[342],"tags":[],"class_list":["post-7996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/7996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=7996"}],"version-history":[{"count":1,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/7996\/revisions"}],"predecessor-version":[{"id":42713,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/7996\/revisions\/42713"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/42716"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=7996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=7996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=7996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}