HOME
ABOUT

Input and Output

Input and Output

Basic Output

print("Hello, World!")
print("Python", "is", "awesome", sep="-")  # Output: Python-is-awesome

Formatted Output

name = "Alice"
age = 25
print(f"{name} is {age} years old")  # f-strings (Python 3.6+)
print("{} is {} years old".format(name, age))  # format() method

User Input

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}, you are {age} years old!")

File Operations

# Writing to a file
with open("example.txt", "w") as file:
    file.write("Hello, File!")

# Reading from a file
with open("example.txt", "r") as file:
    content = file.read()
    print(content)

Related Articles

  • Introduction to Python
  • Setting Up Python Environment
  • Python Syntax Basics
  • Variables and Data Types
  • Operators
  • Input and Output
  • Control Flow: Conditionals
  • Control Flow: Loops
  • Functions
  • Lists and Tuples
  • Dictionaries and Sets
  • String Manipulation
  • How to execute SQL queries (Select, Update, Insert, Delete) effectively using Python?