Easy
  Python
    Guide

Print Statements

Print statements in Python are one of the most fundamental tools for displaying information to users and debugging code. The print() function allows programmers to output text, numbers, and other data directly to the console or terminal window. When you write print("Hello, World!"), Python will display the text "Hello, World!" on the screen. This simple command forms the backbone of many programming tasks and is often the first thing beginners learn when starting their Python journey. The print function can handle various data types including strings, numbers, lists, and even complex objects, making it incredibly versatile for different programming scenarios.

In software development roles, print statements serve as essential debugging tools that help programmers identify and fix issues in their code. When a program isn't working as expected, developers strategically place print statements throughout their code to track variable values, monitor program flow, and pinpoint exactly where problems occur. For instance, a web developer might use print(user_data) to check what information is being received from a form, or print("Reached checkpoint 3") to confirm that a particular section of code is executing properly. This debugging approach is invaluable in professional environments where complex applications need constant maintenance and troubleshooting.

Data analysts and scientists frequently rely on print statements to examine datasets and verify their analysis processes. When working with large spreadsheets or databases, analysts might use commands like print(df.head()) to display the first few rows of data, or print(f"Total sales: £{total_sales:,.2f}") to show formatted financial figures. These statements help professionals quickly assess whether their data processing is working correctly and communicate findings to colleagues. The ability to format output clearly using print statements is particularly valuable when generating reports or presenting results to non-technical stakeholders.

Customer service and support applications heavily utilise print statements to provide users with clear, helpful information. In call centre software, print statements might display customer account details, transaction histories, or troubleshooting steps. For example, a support system might use print(f"Customer {customer_name} has {ticket_count} open tickets") to give representatives immediate context about caller issues. Similarly, automated systems use print statements to guide users through processes, such as print("Please enter your account number followed by the hash key") in telephone banking systems.

Educational technology and training programmes extensively employ print statements to create interactive learning experiences and provide immediate feedback to students. Online coding platforms use print statements to show learners the results of their code execution, whilst educational games might use commands like print("Correct! You've earned 10 points") to acknowledge student progress. In corporate training environments, print statements help create step-by-step tutorials and assessment tools that guide employees through new software or procedures. The immediate visual feedback provided by print statements makes them invaluable for creating engaging, responsive learning materials that help people understand complex concepts through hands-on practice.

Syntax

Some examples of where print statements would be used in real code:


# Example 1: Customer Service System - Displaying account information
customer_name = "Sarah Johnson"
account_balance = 1250.75
last_transaction = "Online purchase - £45.99"
print(f"Customer: {customer_name}") # f-strings allow you to embed variables and expressions directly inside string literals using {curly braces}
print(f"Current balance: £{account_balance:.2f}")
print(f"Last transaction: {last_transaction}")
print("-" * 40)

# Example 2: Data Analysis - Examining sales data
monthly_sales = [12500, 15750, 18200, 14300, 16800]
total_sales = sum(monthly_sales)
average_sales = total_sales / len(monthly_sales)
print(f"Monthly sales figures: {monthly_sales}")
print(f"Total sales for period: £{total_sales:,}")
print(f"Average monthly sales: £{average_sales:,.2f}")
print("-" * 40)

# Example 3: System Administrator - Server monitoring
server_name = "WebServer-01"
cpu_usage = 78.5
memory_usage = 4.2
disk_space = 85.7
print(f"Server Status Report for {server_name}:")
print(f"CPU Usage: {cpu_usage}%")
print(f"Memory Usage: {memory_usage} GB")
print(f"Disk Usage: {disk_space}%")
if cpu_usage > 80:
    print("WARNING: High CPU usage detected!")
print("-" * 40)

# Example 4: Educational Software - Quiz application
student_name = "Alex Thompson"
question_number = 3
correct_answers = 7
total_questions = 10
score_percentage = (correct_answers / total_questions) * 100
print(f"Student: {student_name}")
print(f"Progress: Question {question_number} of {total_questions}")
print(f"Current score: {correct_answers}/{total_questions} ({score_percentage}%)")
if score_percentage >= 70:
    print("Well done! You're passing!")
else:
    print("Keep trying - you can do it!")
print("-" * 40)

# Example 5: E-commerce - Order processing system
order_id = "ORD-2024-0157"
product_name = "Wireless Headphones"
quantity = 2
unit_price = 79.99
delivery_cost = 4.99
total_cost = (quantity * unit_price) + delivery_cost
print(f"Order Confirmation - {order_id}")
print(f"Product: {product_name}")
print(f"Quantity: {quantity}")
print(f"Unit price: £{unit_price}")
print(f"Delivery: £{delivery_cost}")
print(f"Total: £{total_cost:.2f}")
print("Thank you for your order!")  
      

◄ Variables | Input Statements ►